fix(layout): 公共移动 tab bar 不再泄漏到 /admin(DEF-03)
`src/app/layout.tsx` 无条件渲染 `<MobileTabBar />`,于是后台所有路由 (含 /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)。
This commit is contained in:
1 parent
c9b9c886d1
commit
cfd5079dd6
3 files changed
+58
-2
No files matched your search
+4
-2
@@ -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({
|
||||
</ClientLayout>
|
||||
</SiteConfigProvider>
|
||||
</ErrorBoundary>
|
||||
{/* 公共移动 tab bar 留在根布局(main/PageTransition 之外,fixed 定位不受 transform 影响),
|
||||
只按 pathname 在 /admin 下关闭:/admin 是内部系统,露出公共导航会盖住后台内容(DEF-03)。 */}
|
||||
<Suspense fallback={null}>
|
||||
<MobileTabBar />
|
||||
<MobileTabBarGate />
|
||||
</Suspense>
|
||||
<CookieConsent />
|
||||
<BackToTop />
|
||||
|
||||
@@ -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: () => <div data-testid="mobile-tab-bar-mock" />,
|
||||
}));
|
||||
|
||||
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(<MobileTabBarGate />);
|
||||
expect(screen.queryByTestId('mobile-tab-bar-mock')).not.toBeInTheDocument();
|
||||
admin.unmount();
|
||||
|
||||
mockCurrentPath = '/';
|
||||
render(<MobileTabBarGate />);
|
||||
expect(screen.getByTestId('mobile-tab-bar-mock')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -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 <MobileTabBar />;
|
||||
}
|
||||
Reference in new issue
Block a user