2026-04-02 09:23:57 +08:00
|
|
|
import { ComponentType } from "react"
|
|
|
|
|
import { createBrowserRouter } from "react-router-dom"
|
|
|
|
|
import ErrorPage from "@/components/error-page"
|
2026-04-14 11:17:31 +08:00
|
|
|
import EmptyLayout from "@/layout/empty-layout"
|
2026-04-02 09:23:57 +08:00
|
|
|
import HeroLayout from "@/layout/hero-layout"
|
|
|
|
|
|
|
|
|
|
function lazy<T extends { default: ComponentType<unknown> }>(importer: () => Promise<T>) {
|
|
|
|
|
return async () => {
|
|
|
|
|
const module = await importer()
|
|
|
|
|
return {
|
|
|
|
|
Component: module.default,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 10:46:06 +08:00
|
|
|
const hydrateFallbackElement = <div className="px-4 py-6 text-gray-500">页面加载中...</div>
|
|
|
|
|
|
2026-04-02 09:23:57 +08:00
|
|
|
/**
|
|
|
|
|
* Main application router configuration using React Router v6.
|
|
|
|
|
* Defines all routes and their corresponding components.
|
|
|
|
|
*/
|
|
|
|
|
const router = createBrowserRouter(
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
path: "/",
|
|
|
|
|
element: <HeroLayout />,
|
2026-05-07 10:46:06 +08:00
|
|
|
hydrateFallbackElement,
|
2026-04-02 09:23:57 +08:00
|
|
|
errorElement: <ErrorPage />,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
index: true,
|
2026-04-06 17:57:25 +08:00
|
|
|
lazy: lazy(() => import("@/page/firearms")),
|
2026-05-07 10:46:06 +08:00
|
|
|
|
2026-04-06 17:57:25 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "firearms",
|
|
|
|
|
lazy: lazy(() => import("@/page/firearms")),
|
2026-04-02 09:23:57 +08:00
|
|
|
},
|
|
|
|
|
{
|
2026-04-02 10:01:18 +08:00
|
|
|
path: "mod-codes",
|
|
|
|
|
lazy: lazy(() => import("@/page/mod-codes")),
|
2026-04-02 09:23:57 +08:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2026-04-14 11:17:31 +08:00
|
|
|
{
|
|
|
|
|
element: <EmptyLayout />,
|
2026-05-07 10:46:06 +08:00
|
|
|
hydrateFallbackElement,
|
2026-04-14 11:17:31 +08:00
|
|
|
errorElement: <ErrorPage />,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: "login",
|
|
|
|
|
lazy: lazy(() => import("@/page/login")),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2026-04-02 09:23:57 +08:00
|
|
|
],
|
|
|
|
|
{
|
|
|
|
|
basename: "/",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export default router
|