refactor: remvoe old router
This commit is contained in:
parent
2a3e2af528
commit
62cc934035
@ -1,25 +1,13 @@
|
||||
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 { BrowserRouter } from 'react-router-dom';
|
||||
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';
|
||||
@ -43,43 +31,6 @@ declare module '@tanstack/react-router' {
|
||||
}
|
||||
}
|
||||
|
||||
export const AppRoutes: React.FC = React.memo(() => {
|
||||
const { info: userInfo } = useUserStore();
|
||||
const { allowRegister } = useGlobalConfig();
|
||||
|
||||
useInjectWebsiteScript();
|
||||
|
||||
return (
|
||||
<Routes>
|
||||
{userInfo ? (
|
||||
<Route element={<Layout />}>
|
||||
<Route path="/dashboard" element={<DashboardPage />} />
|
||||
<Route path="/monitor/*" element={<MonitorPage />} />
|
||||
<Route path="/website/*" element={<WebsitePage />} />
|
||||
<Route path="/servers" element={<Servers />} />
|
||||
<Route path="/telemetry/*" element={<TelemetryPage />} />
|
||||
<Route path="/settings/*" element={<SettingsPage />} />
|
||||
</Route>
|
||||
) : (
|
||||
<Route>
|
||||
<Route path="/login" element={<Login />} />
|
||||
{allowRegister && <Route path="/register" element={<Register />} />}
|
||||
</Route>
|
||||
)}
|
||||
|
||||
<Route path="/status/:slug" element={<StatusPage />} />
|
||||
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<Navigate to={userInfo ? '/dashboard' : '/login'} replace={true} />
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
);
|
||||
});
|
||||
AppRoutes.displayName = 'AppRoutes';
|
||||
|
||||
export const App: React.FC = React.memo(() => {
|
||||
const rootRef = useRef<HTMLDivElement | null>(null);
|
||||
const colorScheme = useColorSchema();
|
||||
@ -87,6 +38,8 @@ export const App: React.FC = React.memo(() => {
|
||||
colorScheme === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm;
|
||||
const { info: userInfo } = useUserStore();
|
||||
|
||||
useInjectWebsiteScript();
|
||||
|
||||
return (
|
||||
<div ref={rootRef} className="App">
|
||||
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
||||
@ -96,8 +49,7 @@ export const App: React.FC = React.memo(() => {
|
||||
getPopupContainer={() => rootRef.current!}
|
||||
>
|
||||
<TokenLoginContainer>
|
||||
{isDev ? (
|
||||
// Compatible with old routes
|
||||
{/* Compatible with old routes */}
|
||||
<BrowserRouter>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<RouterProvider router={router} context={{ userInfo }} />
|
||||
@ -105,11 +57,6 @@ export const App: React.FC = React.memo(() => {
|
||||
|
||||
<Toaster />
|
||||
</BrowserRouter>
|
||||
) : (
|
||||
<BrowserRouter>
|
||||
<AppRoutes />
|
||||
</BrowserRouter>
|
||||
)}
|
||||
</TokenLoginContainer>
|
||||
</ConfigProvider>
|
||||
</QueryClientProvider>
|
||||
|
Loading…
Reference in New Issue
Block a user