Files
delta-force-guide-web/src/router/index.tsx
T
zihluwang ac76150915 feat: implement user authentication with login functionality
- Add auth-api for handling login requests.
- Update index.ts to export AuthApi.
- Modify HeroLayout to display username or login link based on authentication state.
- Create LoginPage component for user login.
- Update router to include login route with EmptyLayout.
- Configure WebClient to include credentials in requests.
- Add auth-slice for managing authentication state in Redux.
- Update Redux store to include auth reducer.
- Define LoginRequest and User types in types/index.ts.
- Configure Vite to proxy API requests to the backend server.
2026-04-14 11:17:31 +08:00

58 lines
1.3 KiB
TypeScript

import { ComponentType } from "react"
import { createBrowserRouter } from "react-router-dom"
import ErrorPage from "@/components/error-page"
import EmptyLayout from "@/layout/empty-layout"
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,
}
}
}
/**
* Main application router configuration using React Router v6.
* Defines all routes and their corresponding components.
*/
const router = createBrowserRouter(
[
{
path: "/",
element: <HeroLayout />,
errorElement: <ErrorPage />,
children: [
{
index: true,
lazy: lazy(() => import("@/page/firearms")),
},
{
path: "firearms",
lazy: lazy(() => import("@/page/firearms")),
},
{
path: "mod-codes",
lazy: lazy(() => import("@/page/mod-codes")),
},
],
},
{
element: <EmptyLayout />,
errorElement: <ErrorPage />,
children: [
{
path: "login",
lazy: lazy(() => import("@/page/login")),
},
],
},
],
{
basename: "/",
}
)
export default router