mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { Outlet, RouterProvider, createHashRouter } from 'react-router-dom';
|
|
import { LoginPage } from '@/pages/LoginPage';
|
|
import { NotificationContainer } from '@/components/common/NotificationContainer';
|
|
import { ConfirmationModal } from '@/components/common/ConfirmationModal';
|
|
import { MainLayout } from '@/components/layout/MainLayout';
|
|
import { ProtectedRoute } from '@/router/ProtectedRoute';
|
|
import { useLanguageStore, useThemeStore } from '@/stores';
|
|
|
|
function RootShell() {
|
|
return (
|
|
<>
|
|
<NotificationContainer />
|
|
<ConfirmationModal />
|
|
<Outlet />
|
|
</>
|
|
);
|
|
}
|
|
|
|
const router = createHashRouter([
|
|
{
|
|
element: <RootShell />,
|
|
children: [
|
|
{ path: '/login', element: <LoginPage /> },
|
|
{
|
|
path: '/*',
|
|
element: (
|
|
<ProtectedRoute>
|
|
<MainLayout />
|
|
</ProtectedRoute>
|
|
),
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
|
|
function App() {
|
|
const initializeTheme = useThemeStore((state) => state.initializeTheme);
|
|
const language = useLanguageStore((state) => state.language);
|
|
const setLanguage = useLanguageStore((state) => state.setLanguage);
|
|
|
|
useEffect(() => {
|
|
const cleanupTheme = initializeTheme();
|
|
return cleanupTheme;
|
|
}, [initializeTheme]);
|
|
|
|
useEffect(() => {
|
|
setLanguage(language);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []); // 仅用于首屏同步 i18n 语言
|
|
|
|
useEffect(() => {
|
|
document.documentElement.lang = language;
|
|
}, [language]);
|
|
|
|
return <RouterProvider router={router} />;
|
|
}
|
|
|
|
export default App;
|