Skip to content

Instantly share code, notes, and snippets.

@wschenk
Created December 5, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wschenk/082785c4013e641e59b973cfbb677bed to your computer and use it in GitHub Desktop.
Save wschenk/082785c4013e641e59b973cfbb677bed to your computer and use it in GitHub Desktop.
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