-
-
Save Nilanth/e484fd84079c70f0a12601f0402f6d25 to your computer and use it in GitHub Desktop.
Private Route
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
import { | |
Route, | |
Redirect | |
} from 'react-router-dom'; | |
function PrivateRoute({ children, isAuthenticated, ...rest }) { | |
return ( | |
<Route | |
{...rest} | |
render={ | |
({ location }) => ( | |
isAuthenticated | |
? ( | |
children | |
) : ( | |
<Redirect | |
to={{ | |
pathname: '/login', | |
state: { from: location } | |
}} | |
/> | |
)) | |
} | |
/> | |
); | |
} | |
export default PrivateRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment