Skip to content

Instantly share code, notes, and snippets.

@iamnimnul
Created November 5, 2019 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamnimnul/b1f9133bad1b9855a92ef79436779f38 to your computer and use it in GitHub Desktop.
Save iamnimnul/b1f9133bad1b9855a92ef79436779f38 to your computer and use it in GitHub Desktop.
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