import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom'; import { Layout } from './pages/Layout'; import { DashboardPage } from './pages/Dashboard'; import { Login } from './pages/Login'; import { SettingsPage } from './pages/Settings'; import { Servers } from './pages/Servers'; import { useUserStore } from './store/user'; import { Register } from './pages/Register'; import { QueryClientProvider } from '@tanstack/react-query'; import { queryClient } from './api/cache'; import { TokenLoginContainer } from './components/TokenLoginContainer'; import React, { useRef } from 'react'; import { trpc, trpcClient } from './api/trpc'; import { MonitorPage } from './pages/Monitor'; import { WebsitePage } from './pages/Website'; import { useGlobalConfig } from './hooks/useConfig'; import { useInjectWebsiteScript } from './hooks/useInjectWebsiteScript'; import { ConfigProvider, theme } from 'antd'; import { useColorSchema } from './store/settings'; import { StatusPage } from './pages/Status'; import { TelemetryPage } from './pages/Telemetry'; import { isDev } from './utils/env'; import { RouterProvider, createRouter } from '@tanstack/react-router'; import { routeTree } from './routeTree.gen'; import { DefaultNotFound } from './components/DefaultNotFound'; import { TooltipProvider } from './components/ui/tooltip'; import { Toaster } from './components/ui/sonner'; const router = createRouter({ routeTree, context: { userInfo: undefined, }, defaultNotFoundComponent: DefaultNotFound, }); // Register the router instance for type safety declare module '@tanstack/react-router' { interface Register { router: typeof router; } } export const AppRoutes: React.FC = React.memo(() => { const { info: userInfo } = useUserStore(); const { allowRegister } = useGlobalConfig(); useInjectWebsiteScript(); return ( {userInfo ? ( }> } /> } /> } /> } /> } /> } /> ) : ( } /> {allowRegister && } />} )} } /> } /> ); }); AppRoutes.displayName = 'AppRoutes'; export const App: React.FC = React.memo(() => { const rootRef = useRef(null); const colorScheme = useColorSchema(); const algorithm = colorScheme === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm; const { info: userInfo } = useUserStore(); return (
rootRef.current!} > {isDev ? ( // Compatible with old routes ) : ( )}
); }); App.displayName = 'App';