2026-05-24 14:18:39 +08:00
|
|
|
import { createBrowserRouter, Navigate, Outlet } from 'react-router-dom'
|
|
|
|
|
import { useAuthStore } from '../stores/auth'
|
2026-05-24 21:12:23 +08:00
|
|
|
import Layout from '../components/Layout'
|
2026-05-24 14:18:39 +08:00
|
|
|
import LoginPage from '../pages/LoginPage'
|
|
|
|
|
import RegisterPage from '../pages/RegisterPage'
|
|
|
|
|
import ProjectPage from '../pages/ProjectPage'
|
|
|
|
|
import GeneratePage from '../pages/GeneratePage'
|
|
|
|
|
import ResultPage from '../pages/ResultPage'
|
|
|
|
|
|
|
|
|
|
function ProtectedRoute() {
|
|
|
|
|
const isAuthenticated = useAuthStore(s => s.isAuthenticated)
|
|
|
|
|
if (!isAuthenticated) return <Navigate to="/login" replace />
|
|
|
|
|
return <Outlet />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const router = createBrowserRouter([
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
element: <LoginPage />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/register',
|
|
|
|
|
element: <RegisterPage />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
element: <ProtectedRoute />,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
2026-05-24 21:12:23 +08:00
|
|
|
element: <Layout />,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
element: <Navigate to="/projects/proj-default" replace />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/projects/:projectId',
|
|
|
|
|
element: <ProjectPage />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/projects/:projectId/generate',
|
|
|
|
|
element: <GeneratePage />,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/projects/:projectId/tasks/:taskId',
|
|
|
|
|
element: <ResultPage />,
|
|
|
|
|
},
|
|
|
|
|
],
|
2026-05-24 14:18:39 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
])
|