尝试让异步身份验证请求(axios)在react-router中工作。我已经同步使用react-router了一段时间,我理解渲染函数变体,但是在auth-workflow示例[1]的这个组件中:
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={props => (
fakeAuth.isAuthenticated ? (
<Component {...props}/>
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
)
应该扩展到和/或返回的传播运算符...rest
是什么?我认为它是某种异步/静止的呼叫,但我根本不理解它在路线声明中的位置(第二行)。它应该返回路径吗?一个承诺?或者只是以某种方式异步更新身份验证状态(例如,在下一行中设置isAuthenticated
)?
赞赏文档的建议和指示!
编辑:看起来它只是其余道具的通用列表。我想我是在思考它?
[1] https://reacttraining.com/react-router/web/example/auth-workflow