| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- import { lazy } from "react";
- import { createBrowserRouter } from "react-router";
- import { RouterProvider } from "react-router/dom";
- import { channelLoader } from "./api/Channel";
- import { testRoutes } from "./routes/testRoutes";
- import { buildRouteConfig } from "./routes/buildRoutes";
- import { anthologyLoader } from "./api/Article";
- const RootLayout = lazy(() => import("./layouts/Root"));
- const AnonymousLayout = lazy(() => import("./layouts/anonymous"));
- const DashboardLayout = lazy(() => import("./layouts/dashboard"));
- const WorkspaceLayout = lazy(() => import("./layouts/workspace"));
- const WorkspaceEditorLayout = lazy(() => import("./layouts/workspace/editor"));
- const UsersSignIn = lazy(() => import("./pages/users/sign-in"));
- const UsersSignUp = lazy(() => import("./pages/users/sign-up"));
- const UsersForgotPassword = lazy(() => import("./pages/users/forgot-password"));
- const UsersResetPassword = lazy(() => import("./pages/users/reset-password"));
- const DashboardIndex = lazy(() => import("./pages/dashboard/index"));
- const Home = lazy(() => import("./pages/home"));
- const WorkspaceChannel = lazy(() => import("./pages/workspace/channel/list"));
- const WorkspaceChannelShow = lazy(
- () => import("./pages/workspace/channel/show")
- );
- const WorkspaceChannelSetting = lazy(
- () => import("./pages/workspace/channel/setting")
- );
- const WorkspaceTipitaka = lazy(
- () => import("./pages/workspace/tipitaka/bypath")
- );
- const WorkspaceHome = lazy(() => import("./pages/workspace/home"));
- const WorkspaceChat = lazy(() => import("./pages/workspace/chat"));
- const WorkspaceTerm = lazy(() => import("./pages/workspace/term/list"));
- const WorkspaceTermShow = lazy(() => import("./pages/workspace/term/show"));
- const WorkspaceTermEdit = lazy(() => import("./pages/workspace/term/edit"));
- const WorkspaceEditChapter = lazy(
- () => import("./pages/workspace/editor/chapter")
- );
- // 文集
- const WorkspaceAnthologyList = lazy(
- () => import("./pages/workspace/anthology")
- );
- const WorkspaceAnthologyShow = lazy(
- () => import("./pages/workspace/anthology/show")
- );
- // 文章
- const WorkspaceArticleList = lazy(() => import("./pages/workspace/article"));
- // ↓ 新增:TestLayout
- const TestLayout = lazy(() => import("./layouts/test"));
- const router = createBrowserRouter(
- [
- {
- path: "/",
- Component: RootLayout,
- children: [
- { index: true, Component: Home },
- {
- path: "anonymous",
- Component: AnonymousLayout,
- handle: { crumb: "anonymous" },
- children: [
- {
- path: "sign-in",
- Component: UsersSignIn,
- handle: { crumb: "sign-in" },
- },
- {
- path: "sign-up",
- Component: UsersSignUp,
- handle: { crumb: "sign-up" },
- },
- { path: "forgot-password", Component: UsersForgotPassword },
- ],
- },
- {
- path: "dashboard",
- Component: DashboardLayout,
- children: [
- { index: true, Component: DashboardIndex },
- {
- path: "users",
- children: [
- { path: "reset-password", Component: UsersResetPassword },
- ],
- },
- ],
- },
- {
- path: "workspace",
- Component: WorkspaceLayout,
- handle: { id: "workspace.home", crumb: "workspace" },
- children: [
- { index: true, Component: WorkspaceHome },
- {
- path: "ai",
- Component: WorkspaceChat,
- handle: { id: "workspace.ai", crumb: "ai" },
- },
- {
- path: "anthology",
- handle: {
- id: "workspace.anthology",
- crumb: "anthology",
- },
- children: [
- {
- index: true,
- Component: WorkspaceAnthologyList,
- },
- {
- path: ":id",
- Component: WorkspaceAnthologyShow,
- loader: anthologyLoader,
- handle: {
- crumb: (match: { data: { title: string } }) =>
- match.data.title,
- },
- },
- ],
- },
- {
- path: "article",
- handle: {
- id: "workspace.article",
- crumb: "article",
- },
- children: [
- {
- index: true,
- Component: WorkspaceArticleList,
- },
- {
- path: ":id",
- Component: WorkspaceAnthologyShow,
- },
- ],
- },
- {
- path: "tipitaka",
- Component: WorkspaceTipitaka,
- handle: { id: "workspace.tipitaka", crumb: "tipitaka" },
- children: [
- {
- path: ":root",
- Component: WorkspaceTipitaka,
- children: [
- {
- path: ":path",
- Component: WorkspaceTipitaka,
- children: [
- {
- path: ":tag",
- Component: WorkspaceTipitaka,
- },
- ],
- },
- ],
- },
- ],
- },
- {
- path: "channel",
- handle: { id: "workspace.channel", crumb: "channel" },
- children: [
- {
- index: true,
- Component: WorkspaceChannel,
- },
- {
- path: ":channelId",
- loader: channelLoader,
- handle: {
- crumb: (match: { data: { name: string } }) =>
- match.data.name,
- },
- children: [
- {
- index: true,
- Component: WorkspaceChannelShow,
- },
- {
- path: "setting",
- Component: WorkspaceChannelSetting,
- handle: { crumb: "setting" },
- },
- ],
- },
- ],
- },
- {
- path: "term",
- handle: { id: "workspace.term", crumb: "term" },
- Component: WorkspaceTerm,
- },
- {
- path: "edit",
- Component: WorkspaceEditorLayout,
- handle: { crumb: "edit" },
- children: [
- {
- path: "article",
- children: [
- {
- path: ":id",
- children: [
- {
- path: "edit",
- },
- ],
- },
- ],
- },
- {
- path: "anthology",
- children: [{ path: ":id" }],
- },
- {
- path: "series",
- children: [{ path: ":id" }],
- },
- {
- path: "chapter",
- children: [
- {
- path: ":id",
- children: [
- { index: true, Component: WorkspaceEditChapter },
- ],
- },
- ],
- },
- {
- path: "para",
- children: [{ path: ":id" }],
- },
- {
- path: "cs-para",
- children: [{ path: ":id" }],
- },
- {
- path: "wiki",
- handle: { crumb: "wiki" },
- children: [
- {
- path: ":id",
- children: [
- { index: true, Component: WorkspaceTermShow },
- {
- path: "edit",
- Component: WorkspaceTermEdit,
- },
- ],
- },
- ],
- },
- ],
- },
- ],
- },
- // ─── Test 路由:使用 TestLayout + 自动注册 testRoutes ───────────────
- {
- path: "test",
- Component: TestLayout,
- children: [
- // index: 访问 /test 时显示欢迎页(由 TestLayout 内部处理)
- { index: true },
- // 自动将 testRoutes 转换为路由配置
- ...buildRouteConfig(testRoutes),
- ],
- },
- ],
- },
- ],
- { basename: import.meta.env.BASE_URL }
- );
- const Widget = () => {
- return <RouterProvider router={router} />;
- };
- export default Widget;
|