import {
createBrowserRouter,
Navigate,
Outlet,
useParams,
} from "react-router-dom";
import { lazy, Suspense, type ReactNode } from "react";
import { ShieldAlert, Sparkles } from "lucide-react";
import {
LoginPage,
OpenXiangdaPageProvider,
OpenXiangdaProvider,
PublicAccessGate,
RuntimeAuthGuard,
} from "openxiangda/runtime/react";
import { AdminShell } from "@/layouts/AdminShell";
import { AdminDashboardPage } from "@/pages/admin/AdminDashboardPage";
import { NotFoundPage } from "@/pages/states/NotFoundPage";
import { StatePage } from "@/shared/ui";
const servicePrefix = process.env.APP_SERVICE_PREFIX || "/service";
const DataRoutePage = lazy(() =>
import("@/pages/defaults/DataRoutePage").then(module => ({
default: module.DataRoutePage,
})),
);
const FilePreviewRoutePage = lazy(() =>
import("@/pages/defaults/FilePreviewRoutePage").then(module => ({
default: module.FilePreviewRoutePage,
})),
);
const FormRoutePage = lazy(() =>
import("@/pages/defaults/FormRoutePage").then(module => ({
default: module.FormRoutePage,
})),
);
const LoginLogPage = lazy(() =>
import("@/pages/admin/LoginLogPage").then(module => ({
default: module.LoginLogPage,
})),
);
const PublicRegisterPage = lazy(() =>
import("@/pages/public/PublicRegisterPage").then(module => ({
default: module.PublicRegisterPage,
})),
);
const routeElement = (element: ReactNode) => (
}
status="LOADING"
title="加载中"
/>
}
>
{element}
);
const publicAccessFallback = (
}
status="PUBLIC"
title="正在进入公开页面"
/>
);
const publicAccessErrorFallback = (error: { message?: string }) => (
}
status="PUBLIC"
title="链接不可用"
/>
);
function RuntimeRoot() {
const { appType = process.env.OPENXIANGDA_APP_TYPE || "" } = useParams();
return (
);
}
export const router = createBrowserRouter([
{
path: "/view/file-preview",
element: routeElement(),
},
{
path: "/view/submit/:appType/:formUuid",
element: ,
children: [{ index: true, element: routeElement() }],
},
{
path: "/view/:appType",
element: ,
children: [
{ index: true, element: },
{ path: "login", element: },
{
path: "public/register",
element: routeElement(
,
),
},
{
path: "admin",
element: (
),
children: [
{ index: true, element: },
{ path: "data/:formUuid", element: routeElement() },
{ path: "forms/:formUuid/new", element: routeElement() },
{ path: "forms/:formUuid/:formInstId", element: routeElement() },
{ path: "login-logs", element: routeElement() },
{ path: "process/:formUuid/:formInstId", element: routeElement() },
{ path: "*", element: },
],
},
{ path: "file-preview", element: routeElement() },
{ path: "*", element: },
],
},
{ path: "*", element: },
]);