Created
December 5, 2017 22:10
-
-
Save wschenk/082785c4013e641e59b973cfbb677bed 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' | |
class AuthenticatedRoute extends Component { | |
render() { | |
const {authed, component: Component, ...rest} = this.props; | |
if( authed ) { | |
return <Route {...rest} render={(props) => <Component {...props }/>}/> | |
} else { | |
return <Route {...rest} render={(props) => <Redirect to={{pathname: '/session', state: {from: props.location}}} />}/> | |
} | |
} | |
} | |
export default AuthenticatedRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment