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)
}
}