Created
November 5, 2019 11:32
-
-
Save iamnimnul/b1f9133bad1b9855a92ef79436779f38 to your computer and use it in GitHub Desktop.
PrivateRoute in react 16.11 react-router 5.1
This file contains hidden or 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
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