Reputation: 547
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?
Upvotes: 2
Views: 67
Reputation: 41
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} />
Upvotes: 4
Reputation: 5422
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.
Upvotes: 4