App.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Navigate, Outlet } from 'react-router-dom'
  2. import type { RouteObject } from 'react-router-dom'
  3. import { useAuthStore } from '@/stores/authStore'
  4. import Login from '@/pages/Login'
  5. import { AppShell } from '@/components/AppShell'
  6. import Dashboard from '@/pages/Dashboard'
  7. import Collections from '@/pages/Collections'
  8. import Documents from '@/pages/Documents'
  9. import RagTester from '@/pages/RagTester'
  10. import Settings from '@/pages/Settings'
  11. import ProjectsAdmin from '@/pages/ProjectsAdmin'
  12. import KeysAdmin from '@/pages/KeysAdmin'
  13. function ProtectedRoute() {
  14. const loggedIn = useAuthStore((s) => s.loggedIn)
  15. if (!loggedIn) return <Navigate to="/login" replace />
  16. return <AppShell />
  17. }
  18. function AdminRoute() {
  19. const admin = useAuthStore((s) => s.admin)
  20. if (!admin) return <Navigate to="/" replace />
  21. return <Outlet />
  22. }
  23. export const routes: RouteObject[] = [
  24. { path: '/login', element: <Login /> },
  25. {
  26. element: <ProtectedRoute />,
  27. children: [
  28. { index: true, element: <Dashboard /> },
  29. { path: 'collections', element: <Collections /> },
  30. { path: 'documents', element: <Documents /> },
  31. { path: 'rag', element: <RagTester /> },
  32. {
  33. element: <AdminRoute />,
  34. children: [
  35. { path: 'settings', element: <Settings /> },
  36. { path: 'projects', element: <ProjectsAdmin /> },
  37. { path: 'keys', element: <KeysAdmin /> },
  38. ],
  39. },
  40. ],
  41. },
  42. ]