1import { Route, Redirect } from 'react-router'
2
3<Route exact path="/" render={() => (
4 loggedIn ? (
5 <Redirect to="/dashboard"/>
6 ) : (
7 <PublicHomePage/>
8 )
9)}/>
1<ifModule mod_rewrite.c>
2 #######################################################################
3 # GENERAL #
4 #######################################################################
5 # Make apache follow sym links to files
6 Options +FollowSymLinks
7 # If somebody opens a folder, hide all files from the resulting folder list
8 IndexIgnore */*
9 #######################################################################
10 # REWRITING #
11 #######################################################################
12 # Enable rewriting
13 RewriteEngine On
14 # If its not HTTPS
15 RewriteCond %{HTTPS} off
16 # Comment out the RewriteCond above, and uncomment the RewriteCond below if you're using a load balancer (e.g. CloudFlare) for SSL
17 # RewriteCond %{HTTP:X-Forwarded-Proto} !https
18 # Redirect to the same URL with https://, ignoring all further rules if this one is in effect
19 RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R,L]
20 # If we get to here, it means we are on https://
21 # If the file with the specified name in the browser doesn't exist
22 RewriteCond %{REQUEST_FILENAME} !-f
23 # and the directory with the specified name in the browser doesn't exist
24 RewriteCond %{REQUEST_FILENAME} !-d
25 # and we are not opening the root already (otherwise we get a redirect loop)
26 RewriteCond %{REQUEST_FILENAME} !\/$
27 # Rewrite all requests to the root
28 RewriteRule ^(.*) /
29</ifModule>
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