import { CreateSightPage, DevicesPage, EditSightPage, LoginPage, MainPage, SightListPage, MapPage, MediaListPage, MediaPreviewPage, MediaEditPage, CountryListPage, CityListPage, RouteListPage, UserListPage, SnapshotListPage, CarrierListPage, StationListPage, // VehicleListPage, ArticleListPage, // CountryPreviewPage, // VehiclePreviewPage, // CarrierPreviewPage, SnapshotCreatePage, CountryCreatePage, CityCreatePage, CarrierCreatePage, // VehicleCreatePage, CountryEditPage, CityEditPage, UserCreatePage, UserEditPage, // VehicleEditPage, CarrierEditPage, StationCreatePage, StationPreviewPage, StationEditPage, RouteCreatePage, RoutePreview, RouteEditPage, ArticlePreviewPage, } from "@pages"; import { authStore, createSightStore, editSightStore } from "@shared"; import { Layout } from "@widgets"; import { runInAction } from "mobx"; import React, { useEffect } from "react"; import { createBrowserRouter, RouterProvider, Navigate, Outlet, useLocation, } from "react-router-dom"; const PublicRoute = ({ children }: { children: React.ReactNode }) => { const { isAuthenticated } = authStore; if (isAuthenticated) { return ; } return <>{children}; }; const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { const { isAuthenticated } = authStore; const location = useLocation(); if (!isAuthenticated) { return ; } if (location.pathname === "/") { return ; } return <>{children}; }; // Чтобы очистка сторов происходила при смене локации const ClearStoresWrapper: React.FC<{ children: React.ReactNode }> = ({ children, }) => { const location = useLocation(); useEffect(() => { editSightStore.clearSightInfo(); createSightStore.clearCreateSight(); runInAction(() => { editSightStore.hasLoadedCommon = false; }); }, [location]); return <>{children}; }; const router = createBrowserRouter([ { path: "/login", element: ( ), }, { path: "route-preview/:id", element: }, { path: "/", element: ( ), children: [ { index: true, element: }, // Sight { path: "sight", element: }, { path: "sight/create", element: }, { path: "sight/:id/edit", element: }, // Device { path: "devices", element: }, // Map { path: "map", element: }, // Media { path: "media", element: }, { path: "media/:id", element: }, { path: "media/:id/edit", element: }, // Country { path: "country", element: }, { path: "country/create", element: }, // { path: "country/:id", element: }, { path: "country/:id/edit", element: }, // City { path: "city", element: }, { path: "city/create", element: }, // { path: "city/:id", element: }, { path: "city/:id/edit", element: }, // Route { path: "route", element: }, { path: "route/create", element: }, { path: "route/:id/edit", element: }, // User { path: "user", element: }, { path: "user/create", element: }, { path: "user/:id/edit", element: }, // Snapshot { path: "snapshot", element: }, { path: "snapshot/create", element: }, // Carrier { path: "carrier", element: }, { path: "carrier/create", element: }, // { path: "carrier/:id", element: }, { path: "carrier/:id/edit", element: }, // Station { path: "station", element: }, { path: "station/create", element: }, { path: "station/:id", element: }, { path: "station/:id/edit", element: }, // Vehicle // { path: "vehicle", element: }, // { path: "vehicle/create", element: }, // { path: "vehicle/:id", element: }, // { path: "vehicle/:id/edit", element: }, // Article { path: "article", element: }, { path: "article/:id", element: }, // { path: "media/create", element: }, ], }, ]); export const Router = () => { return ; };