Files
react-template/src/router/index.tsx
T

47 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-12-12 09:58:50 +08:00
import { ComponentType } from "react"
2025-09-15 20:19:56 +08:00
import { createBrowserRouter } from "react-router-dom"
import ErrorPage from "@/components/error-page"
2025-12-12 09:58:50 +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,
}
}
}
2025-09-15 20:19:56 +08:00
/**
* Main application router configuration using React Router v6.
* Defines all routes and their corresponding components.
*/
const router = createBrowserRouter(
[
{
path: "/",
2025-12-12 09:58:50 +08:00
element: <HeroLayout />,
errorElement: <ErrorPage />,
children: [
{
index: true,
2025-12-12 09:58:50 +08:00
lazy: lazy(() => import("@/page/home")),
},
{
path: "about",
2025-12-12 09:58:50 +08:00
lazy: lazy(() => import("@/page/about")),
},
{
path: "contact",
2025-12-12 09:58:50 +08:00
lazy: lazy(() => import("@/page/contact")),
},
],
},
],
2025-09-15 20:19:56 +08:00
{
basename: "/",
}
)
2025-09-15 20:19:56 +08:00
export default router