Last active
September 6, 2017 02:30
-
-
Save rob-mcgrail/d72905741cce9e804fad1551195b63e0 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 { connect } from 'react-redux'; | |
import HOCPrivateRoute from 'src/components/utility/PrivateRoute'; | |
function mapStateToProps(state) { | |
return { | |
authenticated: state.auth.authenticated, | |
redirectTo: '/welcome' | |
}; | |
} | |
const PrivateRoute = connect(mapStateToProps)(HOCPrivateRoute); | |
export default PrivateRoute; |
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 from 'react'; | |
import PropTypes from 'prop-types'; | |
import { Route, Redirect, withRouter } from 'react-router-native'; | |
const PrivateRoute = ({ component: Component, ...rest }) => ( | |
<Route | |
{...rest} | |
render={props => ( | |
rest.authenticated ? ( | |
<Component {...props} /> | |
) : ( | |
<Redirect to={{ | |
pathname: rest.redirectTo, | |
state: { from: props.location } | |
}} | |
/> | |
) | |
)} | |
/> | |
); | |
PrivateRoute.propTypes = { | |
component: PropTypes.func.isRequired, | |
location: PropTypes.object.isRequired | |
}; | |
export default withRouter(PrivateRoute); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment