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

144 lines
3.4 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,
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 StudentCoursesPage from "../app/main/courses/student/page";
import InstructorCoursesPage from "../app/main/courses/instructor/page";
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 { CourseGoalForm } from "../components/models/course/editor/form/CourseGoalForm";
import CourseSettingForm from "../components/models/course/editor/form/CourseSettingForm";
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-19 16:06:03 +08:00
import PathsPage from "../app/main/paths/page";
2025-02-06 19:23:48 +08:00
import { adminRoute } from "./admin-route";
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
},
{
path: "paths",
element: <PathsPage></PathsPage>
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-06 19:23:48 +08:00
path: "my-courses",
2025-02-06 16:32:31 +08:00
},
{
2025-02-06 19:23:48 +08:00
path: "profiles",
2025-02-06 16:32:31 +08:00
},
2025-01-03 09:24:46 +08:00
{
path: "courses",
children: [
{
path: "student",
2025-01-08 00:56:15 +08:00
element: (
<WithAuth>
<StudentCoursesPage />
</WithAuth>
),
2025-01-03 09:24:46 +08:00
},
{
path: "instructor",
2025-01-08 00:56:15 +08:00
element: (
<WithAuth>
<InstructorCoursesPage />
</WithAuth>
),
},
],
},
],
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",
element: <CourseEditorLayout></CourseEditorLayout>,
2025-02-06 19:23:48 +08:00
children: [
{
index: true,
element: <CourseBasicForm></CourseBasicForm>,
2024-12-30 08:26:40 +08:00
},
2025-02-06 19:23:48 +08:00
{
path: "goal",
element: <CourseGoalForm></CourseGoalForm>,
2024-12-30 08:26:40 +08:00
},
2025-02-06 19:23:48 +08:00
{
path: "content",
element: (
<CourseContentForm></CourseContentForm>
),
2024-12-30 08:26:40 +08:00
},
2025-02-06 19:23:48 +08:00
{
path: "setting",
element: (
<CourseSettingForm></CourseSettingForm>
),
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
path: ":id?/detail", // 使用 ? 表示 id 参数是可选的
element: <CourseDetailPage />,
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);