2017-06-03 42 views
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) 
    } 
} 

回答

2

更改

{this.props.isAuthenticated && {...this.props}} 

{...(this.props.isAuthenticated && this.props)} 

將做到這一點。