-
-
Save amandeepmittal/e8f59e108a303a1bb8c373fce2dbbdcb to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react'; | |
import { Route, Redirect } from 'react-router-dom'; | |
import auth from './auth-helper'; | |
const PrivateRoute = ({ component: Component, ...rest }) => ( | |
<Route | |
{...rest} | |
render={props => | |
auth.isAuthenticated() ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect | |
to={{ | |
pathname: '/signin', | |
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