| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import { Navigate, Outlet } from 'react-router-dom'
- import type { RouteObject } from 'react-router-dom'
- import { useAuthStore } from '@/stores/authStore'
- import Login from '@/pages/Login'
- import { AppShell } from '@/components/AppShell'
- import Dashboard from '@/pages/Dashboard'
- import Collections from '@/pages/Collections'
- import Documents from '@/pages/Documents'
- import RagTester from '@/pages/RagTester'
- import Settings from '@/pages/Settings'
- import ProjectsAdmin from '@/pages/ProjectsAdmin'
- import KeysAdmin from '@/pages/KeysAdmin'
- function ProtectedRoute() {
- const loggedIn = useAuthStore((s) => s.loggedIn)
- if (!loggedIn) return <Navigate to="/login" replace />
- return <AppShell />
- }
- function AdminRoute() {
- const admin = useAuthStore((s) => s.admin)
- if (!admin) return <Navigate to="/" replace />
- return <Outlet />
- }
- export const routes: RouteObject[] = [
- { path: '/login', element: <Login /> },
- {
- element: <ProtectedRoute />,
- children: [
- { index: true, element: <Dashboard /> },
- { path: 'collections', element: <Collections /> },
- { path: 'documents', element: <Documents /> },
- { path: 'rag', element: <RagTester /> },
- {
- element: <AdminRoute />,
- children: [
- { path: 'settings', element: <Settings /> },
- { path: 'projects', element: <ProjectsAdmin /> },
- { path: 'keys', element: <KeysAdmin /> },
- ],
- },
- ],
- },
- ]
|