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 { AuthPage } from "../AuthPage";
  5. import { LayoutPage } from "../LayoutPage";
  6. import { CProtectedRoute } from "../common/ProtectedRoute";
  7. import { Error404 } from "../common/Error404";
  8. import { useEffect } from "react";
  9. import { connect } from "react-redux";
  10. const Root = ({ onLoad }) => {
  11. useEffect(() => {
  12. onLoad();
  13. }, []);
  14. return (
  15. <Box className="Root">
  16. <Routes>
  17. <Route
  18. path="/auth"
  19. element={
  20. <CProtectedRoute roles={["anon"]} fallback="/admin">
  21. <AuthPage />
  22. </CProtectedRoute>
  23. }
  24. />
  25. <Route path="/404" element={<Error404 />} />
  26. <Route path="/*" element={<LayoutPage />} />
  27. <Route path="*" element={<Navigate to="/404" />} />
  28. </Routes>
  29. </Box>
  30. );
  31. };
  32. export const CRoot = connect(null, { onLoad: () => actionPageStart() })(Root);
  33. export { Root };