September 2018
Beginner
156 pages
3h 28m
English
The <Redirect> component can also be used to redirect the user from a given path to a new path. The <Redirect> component accepts a prop, from, which can be used to specify the path that should match the browser's URL from which the user should be redirected. Also, the path that the user should be redirected to should be specified in the to prop:
<Switch> <Route path="/login" component={LoginComponent} /> <Route path="/user" render={({ match }) => <div> Route with path {match.url}</div> } /> <Redirect from="/home" to="/login" /> <Redirect to="/home" /></Switch>From the preceding example, we can see that when the browser's URL path is /home, the <Redirect> component with the from prop would match ...
Read now
Unlock full access