import { Navigate, Route, RouterProvider, createBrowserRouter, createRoutesFromElements, useLocation, useNavigate, useRouteLoaderData } from 'react-router-dom' import Layout from './components/Layout' import Index from './pages/Index' import Login from './pages/Login' import Register from './pages/Register' import NoMatch from './pages/NoMatch' import { UserProvider } from './store/user' import { ajax } from './utils/fetch' import Engine from './pages/Engine' const router = createBrowserRouter( createRoutesFromElements( } loader={async () => ajax("/api/user")} > } loader={() => ajax("/api/games")} /> } /> } /> } loader={({ params }) => ajax(`/api/engine/${params.gameId}`)} /> {/* } loader={() => ajax(`/api/admin/games`)} /> } loader={() => ({ title: "Новая игра", tasks: [] })} /> */} } /> ) ); function App() { return ( ) } function Auth({ children }) { const baseUser = useRouteLoaderData("root") const { user } = UserProvider.useContainer(); const location = useLocation(); if (!user && !baseUser) { return ; } return children; } export default App