Skip to content

Instantly share code, notes, and snippets.

@gpDA
Created September 10, 2019 17:01
Show Gist options
  • Save gpDA/72b4f9b3d06e96caf8fa415ec0023993 to your computer and use it in GitHub Desktop.
Save gpDA/72b4f9b3d06e96caf8fa415ec0023993 to your computer and use it in GitHub Desktop.
const PrivateRoute = ({component: Component, ...rest}) => {
return(
<Route {...rest} render={props => (
localStorage.getItem('isLogged') === 'true' ?
<Component {...props} />
: <Redirect to="/login" />
)}
/>
)
}
...
<BrowserRouter>
<Switch>
<Route path='/login' component={LogInPage}/>
<PrivateRoute path="/landing" component={LandingPage} />
</Switch>
</BrowserRouter>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment