0
我想弄清楚如何有條件地傳播道具。下面,我在this.props.isAuthenticated1
坐上說與this
意外的標記線{this.props.isAuthenticated && {...this.props}}
一個錯誤:根據條件檢查傳播道具
class ProtectedRoute extends Component {
render() {
const ComponentToRender = this.props.component,
RouteToRender = (
<Route
{this.props.isAuthenticated && {...this.props}}
render={({Component}) =>
(this.props.isAuthenticated ? (<ComponentToRender {...this.props} />) :
(<Redirect
to={{
pathname: '/login',
state: {from: this.props.location
}}}
/>))}
/>)
return (RouteToRender)
}
}