origin/apps/web/src/routes/index.tsx

172 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-07-11 11:00:51 +08:00
import {
2024-12-30 08:26:40 +08:00
createBrowserRouter,
IndexRouteObject,
Link,
NonIndexRouteObject,
2025-02-24 19:10:38 +08:00
useParams,
2024-07-11 11:00:51 +08:00
} from "react-router-dom";
2024-07-22 10:07:05 +08:00
import ErrorPage from "../app/error";
2024-12-30 08:26:40 +08:00
import WithAuth from "../components/utils/with-auth";
import LoginPage from "../app/login";
2025-01-03 09:24:46 +08:00
import HomePage from "../app/main/home/page";
2025-01-08 00:56:15 +08:00
import { CourseDetailPage } from "../app/main/course/detail/page";
2025-01-21 19:48:54 +08:00
import { CourseBasicForm } from "../components/models/course/editor/form/CourseBasicForm";
2025-02-06 19:23:48 +08:00
import CourseContentForm from "../components/models/course/editor/form/CourseContentForm/CourseContentForm";
2025-01-21 19:48:54 +08:00
import CourseEditorLayout from "../components/models/course/editor/layout/CourseEditorLayout";
2025-02-06 16:32:31 +08:00
import { MainLayout } from "../app/main/layout/MainLayout";
import CoursesPage from "../app/main/courses/page";
2025-02-26 23:18:14 +08:00
import PathPage from "../app/main/path/page";
2025-02-06 19:23:48 +08:00
import { adminRoute } from "./admin-route";
2025-02-26 23:18:14 +08:00
import PathEditorPage from "../app/main/path/editor/page";
2025-02-21 17:02:51 +08:00
import { CoursePreview } from "../app/main/course/preview/page";
2025-02-26 21:08:38 +08:00
import MyLearningPage from "../app/main/my-learning/page";
import MyDutyPage from "../app/main/my-duty/page";
2025-02-27 12:22:09 +08:00
import MyPathPage from "../app/main/my-path/page";
import SearchPage from "../app/main/search/page";
2025-03-02 17:45:05 +08:00
import MyDutyPathPage from "../app/main/my-duty-path/page";
2024-09-10 10:31:24 +08:00
interface CustomIndexRouteObject extends IndexRouteObject {
2024-12-30 08:26:40 +08:00
name?: string;
breadcrumb?: string;
2024-09-10 10:31:24 +08:00
}
2024-12-30 08:26:40 +08:00
interface CustomIndexRouteObject extends IndexRouteObject {
name?: string;
breadcrumb?: string;
2024-09-10 10:31:24 +08:00
}
2024-12-30 08:26:40 +08:00
export interface CustomNonIndexRouteObject extends NonIndexRouteObject {
name?: string;
children?: CustomRouteObject[];
breadcrumb?: string;
handle?: {
crumb: (data?: any) => void;
};
}
export type CustomRouteObject =
| CustomIndexRouteObject
| CustomNonIndexRouteObject;
export const routes: CustomRouteObject[] = [
{
path: "/",
errorElement: <ErrorPage />,
handle: {
crumb() {
return <Link to={"/"}></Link>;
},
},
children: [
2024-12-31 15:57:32 +08:00
{
2025-01-03 09:24:46 +08:00
element: <MainLayout></MainLayout>,
children: [
{
index: true,
2025-01-08 00:56:15 +08:00
element: <HomePage />,
2025-02-19 16:06:03 +08:00
},
{
2025-02-26 23:18:14 +08:00
path: "path",
children: [
{
index: true,
element: <PathPage></PathPage>,
},
{
path: "editor/:id?",
2025-03-02 17:45:05 +08:00
element: (
<WithAuth>
<PathEditorPage></PathEditorPage>
</WithAuth>
),
2025-02-27 10:38:48 +08:00
},
],
2025-01-03 09:24:46 +08:00
},
2025-02-06 16:32:31 +08:00
{
path: "courses",
2025-02-06 19:23:48 +08:00
element: <CoursesPage></CoursesPage>,
2025-02-06 16:32:31 +08:00
},
2025-02-27 12:22:09 +08:00
{
path: "my-path",
element: (
<WithAuth>
<MyPathPage></MyPathPage>
</WithAuth>
),
},
2025-02-27 22:58:42 +08:00
{
path: "my-duty-path",
element: (
<WithAuth>
2025-03-02 17:45:05 +08:00
<MyDutyPathPage></MyDutyPathPage>
2025-02-27 22:58:42 +08:00
</WithAuth>
),
},
2025-02-26 21:08:38 +08:00
{
path: "my-duty",
element: (
<WithAuth>
<MyDutyPage></MyDutyPage>
</WithAuth>
),
},
{
path: "my-learning",
element: (
<WithAuth>
<MyLearningPage></MyLearningPage>
</WithAuth>
),
},
2025-02-27 12:22:09 +08:00
{
path: "search",
element: <SearchPage></SearchPage>,
},
2025-02-27 08:25:48 +08:00
{
path: "course/:id?/detail/:lectureId?", // 使用 ? 表示 id 参数是可选的
element: <CourseDetailPage />,
},
2025-01-08 00:56:15 +08:00
],
2024-12-31 15:57:32 +08:00
},
2025-02-26 21:08:38 +08:00
2024-12-31 15:57:32 +08:00
{
path: "course",
2025-01-08 00:56:15 +08:00
children: [
{
2025-01-13 07:52:51 +08:00
path: ":id?/editor",
2025-02-25 16:04:55 +08:00
element: (
2025-02-26 21:08:38 +08:00
<WithAuth>
2025-02-25 16:04:55 +08:00
<CourseEditorLayout></CourseEditorLayout>
</WithAuth>
),
2025-02-06 19:23:48 +08:00
children: [
{
index: true,
2025-02-25 16:04:55 +08:00
element: (
<WithAuth>
<CourseBasicForm></CourseBasicForm>
</WithAuth>
),
2024-12-30 08:26:40 +08:00
},
2025-02-25 16:04:55 +08:00
2025-02-06 19:23:48 +08:00
{
path: "content",
element: (
2025-02-25 16:04:55 +08:00
<WithAuth>
<CourseContentForm></CourseContentForm>
</WithAuth>
2025-02-06 19:23:48 +08:00
),
2024-12-30 08:26:40 +08:00
},
2025-02-06 19:23:48 +08:00
],
2024-12-30 08:26:40 +08:00
},
],
},
2025-02-06 19:23:48 +08:00
adminRoute,
2024-12-30 08:26:40 +08:00
],
},
{
path: "/login",
breadcrumb: "登录",
element: <LoginPage></LoginPage>,
},
];
2024-09-09 18:48:07 +08:00
2024-09-10 10:31:24 +08:00
export const router = createBrowserRouter(routes);