import { CreateSightPage, DevicesPage, EditSightPage, LoginPage, MainPage, SightListPage, MapPage, MediaListPage, MediaPreviewPage, MediaEditPage, CountryListPage, CityListPage, RouteListPage, UserListPage, SnapshotListPage, CarrierListPage, StationListPage, ArticleListPage, SnapshotCreatePage, CountryCreatePage, CityCreatePage, CarrierCreatePage, VehicleCreatePage, VehicleEditPage, CountryEditPage, CityEditPage, UserCreatePage, UserEditPage, CarrierEditPage, StationCreatePage, StationPreviewPage, StationEditPage, RouteCreatePage, RoutePreview, RouteEditPage, ArticlePreviewPage, CountryAddPage, } 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; const need_auth = import.meta.env.VITE_NEED_AUTH == "true"; if (isAuthenticated || !need_auth) { return ; } return <>{children}; }; const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { const { isAuthenticated } = authStore; const need_auth = import.meta.env.VITE_NEED_AUTH == "true"; const location = useLocation(); if (!isAuthenticated && need_auth) { 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: }, { path: "sight", element: }, { path: "sight/create", element: }, { path: "sight/:id/edit", element: }, { path: "devices", element: }, { path: "map", element: }, { path: "media", element: }, { path: "media/:id", element: }, { path: "media/:id/edit", element: }, { path: "country", element: }, { path: "country/create", element: }, { path: "country/add", element: }, { path: "country/:id/edit", element: }, { path: "city", element: }, { path: "city/create", element: }, { path: "city/:id/edit", element: }, { path: "route", element: }, { path: "route/create", element: }, { path: "route/:id/edit", element: }, { path: "user", element: }, { path: "user/create", element: }, { path: "user/:id/edit", element: }, { path: "snapshot", element: }, { path: "snapshot/create", element: }, { path: "carrier", element: }, { path: "carrier/create", element: }, { path: "carrier/:id/edit", element: }, { path: "station", element: }, { path: "station/create", element: }, { path: "station/:id", element: }, { path: "station/:id/edit", element: }, { path: "vehicle/create", element: }, { path: "vehicle/:id/edit", element: }, { path: "article", element: }, { path: "article/:id", element: }, ], }, ]); export const Router = () => { return ; };