Created
July 9, 2019 08:27
-
-
Save AlexLo33/65135d09946204594b64d1c97af4f745 to your computer and use it in GitHub Desktop.
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 { Redirect, Route } from 'react-router-dom'; | |
const PrivateRoute = ({ component: Component, token, ...propsRoute }) => ( | |
<Route | |
{...propsRoute} | |
render={props => ( | |
token !== '' | |
? <Component {...props} /> | |
: ( | |
<Redirect to={{ | |
pathname: '/login', | |
state: { from: props.location }, | |
}} | |
/> | |
) | |
)} | |
/> | |
); | |
export default PrivateRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment