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} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With