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 ; +}