index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Navigate, Route, Routes } from "react-router-dom";
  2. import { Box } from "@mui/material";
  3. import { actionPageStart } from "../../actions/actionPageStart";
  4. import "react-responsive-carousel/lib/styles/carousel.min.css";
  5. import { AuthPage } from "../AuthPage";
  6. import { LayoutPage } from "../LayoutPage";
  7. import { CProtectedRoute } from "../common/ProtectedRoute";
  8. import { Error404 } from "../common/Error404";
  9. import { useEffect } from "react";
  10. import { connect } from "react-redux";
  11. const Root = ({ onLoad }) => {
  12. useEffect(() => {
  13. onLoad();
  14. }, []);
  15. return (
  16. <Box className="Root">
  17. <Routes>
  18. <Route
  19. path="/auth"
  20. element={
  21. <CProtectedRoute roles={["anon"]} fallback="/admin">
  22. <AuthPage />
  23. </CProtectedRoute>
  24. }
  25. />
  26. <Route path="/404" element={<Error404 />} />
  27. <Route path="/*" element={<LayoutPage />} />
  28. <Route path="*" element={<Navigate to="/404" />} />
  29. </Routes>
  30. </Box>
  31. );
  32. };
  33. export const CRoot = connect(null, { onLoad: () => actionPageStart() })(Root);
  34. export { Root };