Reputation: 113
I'm using [email protected]
for routing and I'm having some trouble with the react routing.
Here is my app.js render code:
return (
<div>
<BrowserRouter>
<Context>
{/* Students */}
<Route exact path='/student'><Home /></Route>
<Route path='/student/signup'><SignupScreen /></Route>
{/* Tutors */}
<Route path='/tutor/signup'><TSignupScreen /></Route>
</Context>
</BrowserRouter>
</div>
);
When I visit "/student"
route it renders student signup component but the url is not changing. you can see the image below
Upvotes: 3
Views: 316
Reputation: 3091
Wrap all your routes inside Switch
, which renders the first child that matches the location.
import { BrowserRouter, Route, Switch } from "react-router-dom";
...
<BrowserRouter>
<Context>
<Switch>
{/* Students */}
<Route exact path='/student'><Home /> </Route>
<Route path='/student/signup' > <SignupScreen /> </Route>
{/* Tutors */}
<Route path='/tutor/signup'> <TSignupScreen /> </Route>
</Switch>
</Context>
</BrowserRouter>
Upvotes: 3