我正在使用react-router,并创建了一个PrivateRoute组件,该组件在验证后显示组件,否则重定向到登录页面。如何在反应中添加另一个道具...道具
我想要做的是传递一个额外的道具(认证)在调用者指定的顶部。
我似乎无法得到正确的语法,并搜索“...道具”没有提出任何文档。
这里是我的代码:
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route {...rest} render={(props) => (
this.state.authentication.authenticated() ? (
<Component authentication:{this.state.authentication} {...props}/>
) : (
<Redirect to={{
pathname: '/login',
state: { from: props.location }
}}/>
)
)}/>
);