Open rmn316 opened 5 years ago
A more standard approach with React Router >= 4.x.x . is to create a component which returns a <Route>
or <Redirect>
:
const AuthRequiredRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
isAuthenticated === true
? <Component {...props} />
: <Redirect to={{
pathname: '/login',
state: { from: props.location }
}} />
)} />
)
Then:
<Switch>
<Route path="/logout" component={Logout} />
<Route path="/login" component={Login} />
<AuthRequiredRoute path="/" exact component={KeywordItems} />
</Switch>
What Happened
Application does not automatically redirect a non-authenticated user to the login page.
Outcome
Added a redirect to the login page on the default route page (component). Which will send any non-authenticated user to the login page.