ca3adb0f5b
Comment out `src/router/index.ts` and `src/router/proxy.ts` to temporarily disable the Next.js 16 proxy (auth-driven redirects) and router re-exports. This effectively turns off the centralized route guard logic and stops the proxy from intercepting requests until further iteration.
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
/**
|
|
* 类型化路由常量
|
|
*
|
|
* 集中管理应用中使用的路由路径,与 Flutter `lib/router/app_router.dart` 的
|
|
* `AppRoutes` 一一对应。被服务端组件、客户端组件、`src/proxy.ts` 三端共用。
|
|
*
|
|
* 关键设计:
|
|
* - `as const` 让每个值都是字符串字面量类型,可用于 `PageProps<'/literal'>`。
|
|
* - 不导出 Client-only 模块(`use-auth-gate` 走独立路径导入),保证 Server bundle 不被污染。
|
|
* - 动态深链通过 `ROUTE_BUILDERS` 函数生成,避免手拼字符串。
|
|
*
|
|
* 注意:proxy 路由跳转逻辑(2026-06-15 迁出),但本文件的**类型化常量**仍在
|
|
* 被 9 个组件(auth-screen / chat-header / quota-dialog / DeepLinkPersist /
|
|
* error / not-found / page / sidebar-screen / splash-screen)使用 —— **不能**整体注释。
|
|
*/
|
|
|
|
/** 静态路由字面量 */
|
|
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 PROTECTED_ROUTES: readonly StaticRoute[] = [
|
|
ROUTES.chat,
|
|
ROUTES.sidebar,
|
|
] 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}`;
|