Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 478
My real name Avatar asked Mar 24 '26 04:03

My real name


2 Answers

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.

like image 51
Yannick K Avatar answered Mar 26 '26 19:03

Yannick K


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} />
like image 29
Satyaranjan Acharya Avatar answered Mar 26 '26 19:03

Satyaranjan Acharya