Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PrivateRoute in react 16.11 react-router 5.1
function PrivateRoute({component: Component, isAuthenticated: isAuthenticated, ...rest}) {
return (
<Route
{...rest}
render={props => isAuthenticated ? (<Component {...props} />) : (<Redirect to={{pathname: "/login"}} />)}
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment