1import { Route, Redirect } from 'react-router'
2
3<Route exact path="/" render={() => (
4 loggedIn ? (
5 <Redirect to="/dashboard"/>
6 ) : (
7 <PublicHomePage/>
8 )
9)}/>
1<Route exact path="/">
2 {loggedIn ? <Redirect to="/profile" /> : <HomePage />}
3</Route>
1<Route exact path="/">
2 {loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
3</Route>
1state = { redirect: null };
2
3render() {
4 if (this.state.redirect) {
5 return <Redirect to={this.state.redirect} />
6 }
7 return(
8 // Your Code goes here
9 )
10}
11
12// update the redirect
13 this.setState({ redirect: "/someRoute" });
1<Route exact path="/">
2 {loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
3</Route>
4