router.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { Suspense, lazy } from "react";
  2. import { Switch, Route } from "react-router-dom";
  3. import * as routes from './constants/routes';
  4. import Header from "./containers/Header";
  5. import landingPage from './components/public-components/landingPage';
  6. import Footer from './components/public-components/footer';
  7. import PrivateRouter from './components/common/privateRouter';
  8. import PrivateAdminRouter from './components/common/privateAdminRouter';
  9. import Spinner from "./components/common/spinner";
  10. const notFound = lazy(() => import("./components/public-components/notFound"));
  11. // const permissionDenied = lazy(() => import("./components/public-components/permissionDenied"));
  12. const homePage = lazy(() => import("./components/user-components/homePage"));
  13. const signInPage = lazy(() => import("./containers/auth/SignInPage"));
  14. const signUpPage = lazy(() => import("./containers/auth/SignUpPage"));
  15. const createTestForm = lazy(() => import("./components/user-components/admin-components/createTestForm"));
  16. class Router extends React.Component {
  17. checkUserInLocalStorage = () => {
  18. // localStorage.getItem(token)
  19. }
  20. getSomeUsers() {
  21. fetch('localhost:3306')
  22. .then(res => console.log(res))
  23. .catch(exc => console.warn(exc.message))
  24. }
  25. componentDidMount() {
  26. this.getSomeUsers();
  27. }
  28. render() {
  29. return (
  30. <div className="app">
  31. <Header />
  32. <Suspense fallback={<Spinner />}>
  33. <Switch>
  34. <Route path={routes.LANDING} exact component={landingPage} />
  35. <Route path={routes.SIGN_IN} exact component={signInPage} />
  36. <Route path={routes.SIGN_UP} exact component={signUpPage} />
  37. <Route path={routes.HOME} exact component={homePage} />
  38. <PrivateRouter path={routes.HOME} exact component={homePage} />
  39. <PrivateRouter path={routes.TESTS} exact component={null} />
  40. <PrivateRouter path={routes.CATEGORIES} exact component={null} />
  41. <PrivateRouter path={routes.PROFILE} exact component={null} />
  42. <PrivateAdminRouter path={routes.CREATE_TEST} exact component={createTestForm} />
  43. <PrivateAdminRouter path={routes.CREATE_CATEGORY} exact component={null} />
  44. <PrivateAdminRouter path={routes.DELETE_USER} exact component={null} />
  45. {/* <Route path={routes.PERMISSON_DENIED} exact component={permissionDenied} /> */}
  46. <Route component={notFound} />
  47. </Switch>
  48. </Suspense>
  49. <Footer />
  50. </div>
  51. )
  52. }
  53. }
  54. export default Router;