feat(navigation): 为数字人前台拆分独立页面路由
- 新增对话列表、聊天、角色详情、书架详情及个人资料独立路由 - 导航使用真实链接,补齐历史返回、登录深链与会话草稿恢复 - 搜索筛选由 URL 驱动,修复浏览器返回时丢失筛选的问题 - 补齐路由校验回归、页面加载与异常入口,并同步 README
This commit is contained in:
+18
-2
@@ -1,8 +1,13 @@
|
||||
/** 私有页面会话路由,默认登录后进入数字人空间。 */
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { digitalLoginPath, safeDigitalReturnTo } from "@/lib/digital-routes";
|
||||
|
||||
const protectedRoutes = [
|
||||
"/discover",
|
||||
"/chats",
|
||||
"/characters",
|
||||
"/library",
|
||||
"/profile",
|
||||
"/dashboard",
|
||||
"/tasks",
|
||||
"/schedule",
|
||||
@@ -13,6 +18,7 @@ const protectedRoutes = [
|
||||
const publicRoutes = ["/", "/login"];
|
||||
const cookieName = process.env.ROLE_USER_SESSION_COOKIE || "role_user_session";
|
||||
|
||||
/** 路由级登录保护;深链携带站内回跳目标,不丢失具体聊天地址。 */
|
||||
export function proxy(request: NextRequest) {
|
||||
const path = request.nextUrl.pathname;
|
||||
const hasSession = Boolean(request.cookies.get(cookieName)?.value);
|
||||
@@ -22,16 +28,26 @@ export function proxy(request: NextRequest) {
|
||||
const isPublic = publicRoutes.includes(path);
|
||||
|
||||
if (isProtected && !hasSession) {
|
||||
return NextResponse.redirect(new URL("/login", request.url));
|
||||
return NextResponse.redirect(
|
||||
new URL(digitalLoginPath(path + request.nextUrl.search), request.url),
|
||||
);
|
||||
}
|
||||
|
||||
if (isPublic && hasSession) {
|
||||
return NextResponse.redirect(new URL("/discover", request.url));
|
||||
return NextResponse.redirect(
|
||||
new URL(
|
||||
path === "/login"
|
||||
? safeDigitalReturnTo(request.nextUrl.searchParams.get("next"))
|
||||
: "/discover",
|
||||
request.url,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
/** 只拦截业务页面,不影响 BFF、静态资源和安装文件。 */
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/((?!api|_next/static|_next/image|manifest.webmanifest|sw.js|.*\\..*).*)",
|
||||
|
||||
Reference in New Issue
Block a user