From cfd5079dd6af49de35c73216ac0d500d97ee8ef0 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Wed, 25 Nov 2026 08:59:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(layout):=20=E5=85=AC=E5=85=B1=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=20tab=20bar=20=E4=B8=8D=E5=86=8D=E6=B3=84=E6=BC=8F?= =?UTF-8?q?=E5=88=B0=20/admin=EF=BC=88DEF-03=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `src/app/layout.tsx` 无条件渲染 ``,于是后台所有路由 (含 /admin/login)在 390 档都被「首页/行业/能力/洞察/联系」这条 fixed 底栏盖住 —— 2026-10-24 全站验收实测 18/18 命中(9 路由 × 明暗)。 改用 `MobileTabBarGate`:按 pathname 在 `/admin*` 返回 null。 它仍留在根布局(main/PageTransition 之外,fixed 定位不受 transform 影响)。 ⚠ 这个 gate 组件此前就在树里,但**没有任何调用点** —— check:dead 把它判成 「仅测试/死链引用」。本次接线后 dead 归零,也是「修复停在 stash 没落地」的 一处物证(见 docs/lessons-learned.md §5.61)。 --- src/app/layout.tsx | 6 ++- .../layout/mobile-tab-bar-gate.test.tsx | 39 +++++++++++++++++++ src/components/layout/mobile-tab-bar-gate.tsx | 15 +++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/components/layout/mobile-tab-bar-gate.test.tsx create mode 100644 src/components/layout/mobile-tab-bar-gate.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8bfdc66f..3edc67f4 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,7 +9,7 @@ import { PerformanceTracker } from "@/components/analytics/PerformanceTracker"; import { OutboundLinkTracker } from "@/components/analytics/OutboundLinkTracker"; import { ScrollDepthTracker } from "@/components/analytics/ScrollDepthTracker"; import { OrganizationSchema, WebsiteSchema, LocalBusinessSchema } from "@/components/seo/structured-data"; -import { MobileTabBar } from "@/components/layout/mobile-tab-bar"; +import { MobileTabBarGate } from "@/components/layout/mobile-tab-bar-gate"; import { ErrorBoundary } from "@/components/ui/error-boundary"; import { ScrollProgress } from "@/components/ui/scroll-progress"; import { MotionProvider } from "@/components/ui/motion-provider"; @@ -214,8 +214,10 @@ export default async function RootLayout({ + {/* 公共移动 tab bar 留在根布局(main/PageTransition 之外,fixed 定位不受 transform 影响), + 只按 pathname 在 /admin 下关闭:/admin 是内部系统,露出公共导航会盖住后台内容(DEF-03)。 */} - + diff --git a/src/components/layout/mobile-tab-bar-gate.test.tsx b/src/components/layout/mobile-tab-bar-gate.test.tsx new file mode 100644 index 00000000..3570754a --- /dev/null +++ b/src/components/layout/mobile-tab-bar-gate.test.tsx @@ -0,0 +1,39 @@ +import { describe, it, expect, jest } from '@jest/globals'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; + +let mockCurrentPath = '/'; +jest.mock('next/navigation', () => ({ + usePathname: () => mockCurrentPath, +})); + +jest.mock('./mobile-tab-bar', () => ({ + MobileTabBar: () =>
, +})); + +import { MobileTabBarGate, shouldRenderMobileTabBar } from './mobile-tab-bar-gate'; + +describe('MobileTabBarGate', () => { + it('不在 /admin 下渲染公共 tab bar', () => { + expect(shouldRenderMobileTabBar('/admin')).toBe(false); + expect(shouldRenderMobileTabBar('/admin/login')).toBe(false); + expect(shouldRenderMobileTabBar('/admin/content/news')).toBe(false); + }); + + it('营销路由继续渲染 tab bar', () => { + expect(shouldRenderMobileTabBar('/')).toBe(true); + expect(shouldRenderMobileTabBar('/products')).toBe(true); + expect(shouldRenderMobileTabBar('/privacy')).toBe(true); + }); + + it('按 pathname 实际 gate', () => { + mockCurrentPath = '/admin'; + const admin = render(); + expect(screen.queryByTestId('mobile-tab-bar-mock')).not.toBeInTheDocument(); + admin.unmount(); + + mockCurrentPath = '/'; + render(); + expect(screen.getByTestId('mobile-tab-bar-mock')).toBeInTheDocument(); + }); +}); diff --git a/src/components/layout/mobile-tab-bar-gate.tsx b/src/components/layout/mobile-tab-bar-gate.tsx new file mode 100644 index 00000000..fe6725d1 --- /dev/null +++ b/src/components/layout/mobile-tab-bar-gate.tsx @@ -0,0 +1,15 @@ +'use client'; + +import { usePathname } from 'next/navigation'; +import { MobileTabBar } from './mobile-tab-bar'; + +/** /admin 是内部系统,不应出现公共移动导航;导出让单测钉住边界。 */ +export function shouldRenderMobileTabBar(pathname: string): boolean { + return !pathname.startsWith('/admin'); +} + +export function MobileTabBarGate() { + const pathname = usePathname(); + if (!shouldRenderMobileTabBar(pathname)) {return null;} + return ; +}