From 69c8c14c91ad5f56dbccd890ad2ef5b2c46e8e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=91=A3=E5=AE=8F=E5=87=AF?= Date: Mon, 15 Jun 2026 20:50:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(nav):=20=E4=BF=AE=E5=A4=8D=E9=97=AE?= =?UTF-8?q?=E7=AD=94=E6=A2=B3=E7=90=86=E7=AD=89=E5=B8=A6=E5=AD=90=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=AF=BC=E8=88=AA=E9=AB=98?= =?UTF-8?q?=E4=BA=AE=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KnowledgeBasePage 加载后自动跳转至 /knowledge/:noteId,原精确路径匹配 导致顶栏和侧边栏选中态丢失。将 hasActiveChild / isItemActive / menuItemContainsPath 等 8 处判断统一改为前缀匹配 (pathname === path || pathname.startsWith(path + "/")), 覆盖浅色侧边栏、深色侧边栏、顶部导航栏三套组件。 Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/page-sidebar-dark.tsx | 4 +- frontend-web/src/components/page-sidebar.tsx | 8 +- .../workspace/messages/message-list.tsx | 36 +++- .../workspace/workspace-nav-menu.tsx | 11 +- .../workspace/workspace-sidebar.tsx | 2 +- .../src/core/page-layout/sidebar-menu.ts | 164 ++++++++++-------- .../src/pages/LightAppManagementPage.tsx | 2 +- frontend-web/src/pages/StrategyRoutes.tsx | 2 + frontend-web/src/pages/WorkspaceRoutes.tsx | 10 +- .../src/strategy-components/Header.tsx | 23 +-- 10 files changed, 161 insertions(+), 101 deletions(-) diff --git a/frontend-web/src/components/page-sidebar-dark.tsx b/frontend-web/src/components/page-sidebar-dark.tsx index 15b6f8c8..af274aff 100644 --- a/frontend-web/src/components/page-sidebar-dark.tsx +++ b/frontend-web/src/components/page-sidebar-dark.tsx @@ -54,7 +54,7 @@ export function PageSidebarDark({ collapsed, onToggleCollapsed }: PageSidebarDar }; const hasActiveChild = (item: MenuItem): boolean => { - if (item.path && pathname === item.path) { + if (item.path && (pathname === item.path || pathname.startsWith(item.path + "/"))) { return true; } @@ -153,7 +153,7 @@ export function PageSidebarDark({ collapsed, onToggleCollapsed }: PageSidebarDar inWujieEnv ? item.id === activeTopId : item.path - ? pathname === item.path + ? pathname === item.path || pathname.startsWith(item.path + "/") : hasActiveChild(item); const handleSidebarItemClick = (item: MenuItem) => { if (inWujieEnv) { diff --git a/frontend-web/src/components/page-sidebar.tsx b/frontend-web/src/components/page-sidebar.tsx index 42b556fe..4ad89043 100644 --- a/frontend-web/src/components/page-sidebar.tsx +++ b/frontend-web/src/components/page-sidebar.tsx @@ -42,7 +42,7 @@ type PageSidebarProps = { type SettingsSection = "account" | "appearance" | "memory" | "tools" | "about"; const hasActiveChild = (item: MenuItem, pathname: string): boolean => { - if (item.path && pathname === item.path) { + if (item.path && (pathname === item.path || pathname.startsWith(item.path + "/"))) { return true; } return item.children?.some((child) => hasActiveChild(child, pathname)) ?? false; @@ -116,7 +116,9 @@ function SecondaryNavSidebar() { const secondaryItems = activeTopItem?.children ?? []; const isItemActive = (item: MenuItem) => - item.path ? pathname === item.path : hasActiveChild(item, pathname); + item.path + ? pathname === item.path || pathname.startsWith(item.path + "/") + : hasActiveChild(item, pathname); const handleItemClick = (item: MenuItem) => { const path = item.path ?? findFirstRoutePath(item.children); @@ -210,7 +212,7 @@ function SecondaryNavSidebar() { {thirdItems.map((child) => { const ChildIcon = child.icon; const childActive = child.path - ? pathname === child.path + ? pathname === child.path || pathname.startsWith(child.path + "/") : hasActiveChild(child, pathname); return (