Created
May 27, 2019 14:04
-
-
Save Wellers0n/0cc2cfc942d51bba9b384fec003b1e06 to your computer and use it in GitHub Desktop.
private Router
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
// privateRouter.js | |
import React from 'react'; | |
import { Route, Redirect } from 'react-router-dom'; | |
import {isAuthenticated} from './../auth' | |
const PrivateRouter = ({component: Component, ...rest}) => { | |
return ( | |
<Route {...rest} render={(props) => ( | |
isAuthenticated() ? ( | |
<div> | |
<Component {...props}/> | |
</div> | |
) : <Redirect to="/"}/> | |
)} /> | |
) | |
} | |
export default PrivateRouter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment