Created
November 30, 2018 19:01
-
-
Save binhtran04/31909eef58e15ecdc379ec07e9753c01 to your computer and use it in GitHub Desktop.
Private route component
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
import React from 'react'; | |
import { Route, Redirect } from 'react-router-dom'; | |
import { isLogin } from '../utils'; | |
const PrivateRoute = ({component: Component, ...rest}) => { | |
return ( | |
// Show the component only when the user is logged in | |
// Otherwise, redirect the user to /signin page | |
<Route {...rest} render={props => ( | |
isLogin() ? | |
<Component {...props} /> | |
: <Redirect to="/signin" /> | |
)} /> | |
); | |
}; | |
export default PrivateRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment