I have this PrivateRoute
component (from the docs):
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
isAuthenticated ? (
<Component {...props}/>
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
)
I would like to change isAuthenticated
to an aysnc request isAuthenticated()
. However, before the response has returned the page redirects.
To clarify, the isAuthenticated
function is already set up.
How can I wait for the async call to complete before deciding what to display?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…