router.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { Suspense, lazy } from "react";
  2. import { Switch, Route, withRouter } from "react-router-dom";
  3. import { connect } from 'react-redux';
  4. import { tokenAuth } from './actions/auth/tokenAuth'
  5. import Header from "./containers/header";
  6. import Footer from './components/public-components/footer';
  7. import Spinner from "./components/common/spinner";
  8. import ProtectedRoute from './components/common/protectedRoute';
  9. import config from './components/common/protectedRoute/config';
  10. import fakeToken from './utils/token'
  11. import { bindActionCreators } from "redux";
  12. class Router extends React.Component {
  13. render() {
  14. const { user, tokenAuth } = this.props;
  15. return (
  16. <div className="app">
  17. <Header />
  18. <Suspense fallback={<Spinner />}>
  19. <Switch>
  20. {config.map(route =>
  21. <ProtectedRoute
  22. path={route.path}
  23. component={route.component}
  24. access={route.access}
  25. user={user}
  26. key={route}
  27. tokenAuth={tokenAuth}
  28. exact
  29. />
  30. )}
  31. </Switch>
  32. </Suspense>
  33. <Footer />
  34. </div>
  35. )
  36. }
  37. }
  38. const mapStateToProps = state => ({
  39. user: state.user
  40. })
  41. const mapDispatchToProps = dispatch => bindActionCreators({ tokenAuth }, dispatch);
  42. export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Router));