Created
January 7, 2018 22:16
-
-
Save mcshiz/9511110f93d6f61aa691a08df1168e89 to your computer and use it in GitHub Desktop.
React Router v4 Private Route with Redux props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PrivateRoute = ({component: Component, ...rest}) => { | |
return ( | |
<Route | |
{...rest} | |
render={(props) => rest.authenticated === true | |
? <Component {...rest} {...props} /> | |
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />} | |
/> | |
) | |
}; | |
<PrivateRoute exact path="/dashboard" component={Dashboard} {...this.props}/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment