Created
November 30, 2018 19:04
-
-
Save binhtran04/a4ace6bfbefe3077bf9e7b5f4fec7b37 to your computer and use it in GitHub Desktop.
Public 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 PublicRoute = ({component: Component, restricted, ...rest}) => { | |
return ( | |
// restricted = false meaning public route | |
// restricted = true meaning restricted route | |
<Route {...rest} render={props => ( | |
isLogin() && restricted ? | |
<Redirect to="/dashboard" /> | |
: <Component {...props} /> | |
)} /> | |
); | |
}; | |
export default PublicRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment