Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <Provider store={store}>
  2. <Router>
  3. <React.Suspense fallback={loading()}>
  4. <Route exact path="/login" name="Login Page" render={props => <Login {...props}/>} />
  5. <Route exact path="/register" name="Register Page" render={props => <Register {...props}/>} />
  6. <Route exact path="/404" name="Page 404" render={props => <Page404 {...props}/>} />
  7. <Route exact path="/500" name="Page 500" render={props => <Page500 {...props}/>} />
  8. <Switch>
  9. <PrivateRoute exact path="/" component={DefaultLayout} />
  10. </Switch>
  11. </React.Suspense>
  12. </Router>
  13. </Provider>
  14.  
  15. import React from "react";
  16. import { Route, Redirect } from "react-router-dom";
  17. import { connect } from "react-redux";
  18. import PropTypes from "prop-types";
  19.  
  20. const PrivateRoute = ({ component: Component, auth, ...rest }) => (
  21. <Route
  22. {...rest}
  23. render={props =>
  24. auth.isAuthenticated === true ? (
  25. <Component {...props} />
  26. ) : (
  27. <Redirect to="/login" />
  28. )
  29. }
  30. />
  31. );
  32.  
  33. PrivateRoute.propTypes = {
  34. auth: PropTypes.object.isRequired
  35. };
  36.  
  37. const mapStateToProps = state => ({
  38. auth: state.auth
  39. });
  40.  
  41. export default connect(mapStateToProps)(PrivateRoute);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement