Skip to content

Instantly share code, notes, and snippets.

@mcshiz
Created January 7, 2018 22:16
Show Gist options
  • Save mcshiz/9511110f93d6f61aa691a08df1168e89 to your computer and use it in GitHub Desktop.
Save mcshiz/9511110f93d6f61aa691a08df1168e89 to your computer and use it in GitHub Desktop.
React Router v4 Private Route with Redux props
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