【发布时间】:2018-02-20 02:00:26
【问题描述】:
我有这个PrivateRoute 组件(来自文档):
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
isAuthenticated ? (
<Component {...props}/>
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
)
我想将 isAuthenticated 更改为 aysnc 请求 isAuthenticated()。但是,在响应返回之前页面重定向。
为了澄清,isAuthenticated 函数已经设置好了。
如何在决定显示什么之前等待异步调用完成?
【问题讨论】:
标签: reactjs react-router react-router-v4