Created
July 3, 2018 14:34
-
-
Save barraponto/c5a478469a369196b3f3f806be385262 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 from "react"; | |
import { Route, Redirect } from "react-router-dom"; | |
import { connect } from "react-redux"; | |
const PrivateRedirect = (props) => ( | |
<Redirect to={{ pathname: "/login", state: { from: props.location } }} />); | |
const PrivateRoute = ({ component, loggedIn, ...passThroughProps }) => { | |
const Component = loggedIn ? component : PrivateRedirect; | |
return <Route component={Component} {...passThroughProps} />; | |
}; | |
const mapStateToProps = (state, props) => ({ loggedIn: state.loggedIn }); | |
export default connect(mapStateToProps)(PrivateRoute); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment