简体   繁体   中英

How to implement React route?

Im new on React, i've got a problem about react route. Let's say i have email verification page and register page, and this is my route code

    <Switch>
        <Route path="/register" component={Register} />
        <Route path="/register/emailverification" component={EmailVerification} />
    </Switch>

when i go to

localhost/register/emailverification

i want it to render email verifation page but i dont know why its render register page?

You should use:

<Route exact path="/register" component={Register} />
<Route exact path="/register/emailverification" component={EmailVerification} />

If you only want to render one or the other.

Make sure to use keyword 'exact' in all the 'Route' components or else it will load both parent as well child routers which are subsets of your browser url. Also it is always better to add a default router with path = '/'

<Route exact path="/register" component={Register} />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM