2026-02-22 20:10:11 +08:00
|
|
|
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
|
import { useAuthStore } from './stores/authStore';
|
|
|
|
|
import LoginPage from './pages/LoginPage';
|
2026-02-24 18:18:27 +08:00
|
|
|
import RegisterPage from './pages/RegisterPage';
|
2026-02-22 20:10:11 +08:00
|
|
|
import DashboardPage from './pages/DashboardPage';
|
|
|
|
|
import DocumentsPage from './pages/DocumentsPage';
|
|
|
|
|
import TodosPage from './pages/TodosPage';
|
|
|
|
|
import ImagesPage from './pages/ImagesPage';
|
2026-02-24 18:18:27 +08:00
|
|
|
import SettingsPage from './pages/SettingsPage';
|
2026-02-22 20:10:11 +08:00
|
|
|
import Layout from './components/Layout';
|
|
|
|
|
|
|
|
|
|
const queryClient = new QueryClient({
|
|
|
|
|
defaultOptions: {
|
|
|
|
|
queries: {
|
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
|
retry: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
|
|
|
|
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
|
return <Navigate to="/login" replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
|
return (
|
|
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
|
<BrowserRouter>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/login" element={<LoginPage />} />
|
2026-02-24 18:18:27 +08:00
|
|
|
<Route path="/register" element={<RegisterPage />} />
|
2026-02-22 20:10:11 +08:00
|
|
|
<Route
|
|
|
|
|
path="/"
|
|
|
|
|
element={
|
|
|
|
|
<ProtectedRoute>
|
|
|
|
|
<Layout />
|
|
|
|
|
</ProtectedRoute>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Route index element={<Navigate to="/dashboard" replace />} />
|
|
|
|
|
<Route path="dashboard" element={<DashboardPage />} />
|
|
|
|
|
<Route path="documents" element={<DocumentsPage />} />
|
|
|
|
|
<Route path="todos" element={<TodosPage />} />
|
|
|
|
|
<Route path="images" element={<ImagesPage />} />
|
2026-02-24 18:18:27 +08:00
|
|
|
<Route path="settings" element={<SettingsPage />} />
|
2026-02-22 20:10:11 +08:00
|
|
|
</Route>
|
|
|
|
|
</Routes>
|
|
|
|
|
</BrowserRouter>
|
|
|
|
|
</QueryClientProvider>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default App;
|