Guest User

Untitled

a guest
Mar 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. import React from 'react'
  2. import { connect } from 'react-redux'
  3. import { isAuthenticated } from '../../reducers'
  4. import { Route, Redirect } from 'react-router-dom'
  5.  
  6. let PrivateRoute = ({ component: Component, isAuthenticated, ...rest}) => (
  7. <Route {...rest} render={(props) => (
  8. isAuthenticated
  9. ? <Component {...props} />
  10. : <Redirect to='/login' />
  11. )} />
  12. )
  13.  
  14. const mapStateToProps = state => ({
  15. isAuthenticated: isAuthenticated(state)
  16. })
  17.  
  18. export default connect(mapStateToProps, undefined)(PrivateRoute)
Add Comment
Please, Sign In to add comment