I'm following an online course and creating a private route component that redirects users based on an isAuthenticated state, I logged the state and it returned the else part even though the state was true.
<Route
{...rest}
render={props =>
isAuthenticated === true ? (
<Redirect to="/login2" />
) : (
<Redirect to="/login3" />
)
}
/>
it redirects to login3 even if the state is true.
<Route {...rest} render={props => props.isAuthenticated === true ? ( <Redirect to="/login2" /> ) : ( <Redirect to="/login3" /> ) } />
– user2063635isAuthenticated
as beingstate
, notprops
. If that indeed is the issue, please read up on the difference here. – Brian Thompson