Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react'
- import { connect } from 'react-redux'
- import { isAuthenticated } from '../../reducers'
- import { Route, Redirect } from 'react-router-dom'
- let PrivateRoute = ({ component: Component, isAuthenticated, ...rest}) => (
- <Route {...rest} render={(props) => (
- isAuthenticated
- ? <Component {...props} />
- : <Redirect to='/login' />
- )} />
- )
- const mapStateToProps = state => ({
- isAuthenticated: isAuthenticated(state)
- })
- export default connect(mapStateToProps, undefined)(PrivateRoute)
Add Comment
Please, Sign In to add comment