refactor: move ROUTES from @/lib/routes to @/router/routes
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 类型化路由常量
|
||||
*
|
||||
* 集中管理应用中使用的路由路径,与 Flutter `lib/router/app_router.dart` 的
|
||||
* `AppRoutes` 一一对应。被服务端组件、客户端组件、`src/proxy.ts` 三端共用。
|
||||
*
|
||||
* 关键设计:
|
||||
* - `as const` 让每个值都是字符串字面量类型,可用于 `PageProps<'/literal'>`。
|
||||
* - 不导出 Client-only 模块(`use-auth-gate` 走独立路径导入),保证 Server bundle 不被污染。
|
||||
* - 动态深链通过 `ROUTE_BUILDERS` 函数生成,避免手拼字符串。
|
||||
*/
|
||||
|
||||
/** 静态路由字面量 */
|
||||
export const ROUTES = {
|
||||
root: "/",
|
||||
splash: "/splash",
|
||||
chat: "/chat",
|
||||
auth: "/auth",
|
||||
sidebar: "/sidebar",
|
||||
} as const;
|
||||
|
||||
export type StaticRoute = (typeof ROUTES)[keyof typeof ROUTES];
|
||||
|
||||
/** 动态深链构造器 */
|
||||
export const ROUTE_BUILDERS = {
|
||||
chatDeviceId: (deviceId: string): `/chat/deviceid/${string}` =>
|
||||
`/chat/deviceid/${encodeURIComponent(deviceId)}` as const,
|
||||
} as const;
|
||||
|
||||
/** 仅未登录态可见的路由(命中后已登录用户应跳走) */
|
||||
export const AUTH_ONLY_ROUTES: readonly StaticRoute[] = [
|
||||
ROUTES.splash,
|
||||
ROUTES.auth,
|
||||
] as const;
|
||||
|
||||
/** 公开路由(游客态也允许访问) */
|
||||
export const PUBLIC_ROUTES: readonly StaticRoute[] = [
|
||||
ROUTES.chat,
|
||||
ROUTES.sidebar,
|
||||
] as const;
|
||||
|
||||
/** 所有静态路由,供 `proxy.ts` matcher 与未来 sitemap 使用 */
|
||||
export const ALL_STATIC_ROUTES: readonly StaticRoute[] = [
|
||||
ROUTES.splash,
|
||||
ROUTES.chat,
|
||||
ROUTES.auth,
|
||||
ROUTES.sidebar,
|
||||
] as const;
|
||||
|
||||
/** 联合路由类型,包含静态路由与已知动态路由 */
|
||||
export type Route = StaticRoute | `/chat/deviceid/${string}`;
|
||||
Reference in New Issue
Block a user