From dc196aca8fd859b340f79c80d75c9fec9c86d905 Mon Sep 17 00:00:00 2001 From: bootx Date: Mon, 20 Jul 2026 15:52:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(router):=20=E8=81=9A=E5=90=88=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E9=A1=B5=E6=B5=8F=E8=A7=88=E5=99=A8=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E4=B8=8D=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - mobile: Aggregate 父级补 meta.title,子路由(entry/unsupported/各环境页)自动继承 - pc: PcAggregate/PcAggregateUnsupported 补 meta.title - pc: 新增 router-guards 挂载 afterEach 切换 document.title(原 PC 端全站缺守卫,顺带修复) --- src/mobile/router/modules.ts | 4 ++++ src/pc/router/index.ts | 5 +++++ src/pc/router/router-guards.ts | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/pc/router/router-guards.ts diff --git a/src/mobile/router/modules.ts b/src/mobile/router/modules.ts index 14e7ba9..7251d6d 100644 --- a/src/mobile/router/modules.ts +++ b/src/mobile/router/modules.ts @@ -57,6 +57,10 @@ const routeModuleList: Array = [ path: RoutePath.AGGREGATE_GROUP, name: 'Aggregate', component: Layout, + // 父级声明 title,子路由(unsupported / 各环境页 / entry)由 vue-router 的 to.meta 合并自动继承 + meta: { + title: '收银台', + }, children: [ // 非宿主提示:静态 path 段 { diff --git a/src/pc/router/index.ts b/src/pc/router/index.ts index 5be70fe..5bd29c7 100644 --- a/src/pc/router/index.ts +++ b/src/pc/router/index.ts @@ -1,6 +1,7 @@ import type { App } from 'vue' import type { RouteRecordRaw } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router' +import { createPcRouterGuards } from '@/pc/router/router-guards' import { otherDeviceExclusives } from '@/shared/router/exclusive' import { RoutePath } from '@/shared/router/paths' @@ -31,12 +32,14 @@ const routes: RouteRecordRaw[] = [ path: RoutePath.AGGREGATE_UNSUPPORTED, name: 'PcAggregateUnsupported', component: () => import('@/pc/views/aggregate/Unsupported.vue'), + meta: { title: '收银台' }, }, // 聚合扫码支付(跨端) { path: RoutePath.AGGREGATE, name: 'PcAggregate', component: () => import('@/pc/views/aggregate/Index.vue'), + meta: { title: '收银台' }, }, // 商户对账单(PC 独占:移动端由注册表派生 device-only 存根) { @@ -108,6 +111,8 @@ const pcRouter = createRouter({ export function setupPCRouter(app: App) { app.use(pcRouter) + // 挂载守卫:依据路由 meta.title 切换浏览器标题 + createPcRouterGuards(pcRouter) } export { pcRouter } diff --git a/src/pc/router/router-guards.ts b/src/pc/router/router-guards.ts new file mode 100644 index 0000000..e123ded --- /dev/null +++ b/src/pc/router/router-guards.ts @@ -0,0 +1,21 @@ +import type { Router } from 'vue-router' + +/** + * PC 端路由守卫 + * + * 仅处理 document.title 切换:当目标路由(或其 matched 链上任意父级) + * 声明了 meta.title 时,更新为该标题;否则保留当前 title(通常为 + * 站点 systemName,由 [applyWebsiteBranding] 设置)。 + * + * 与 mobile/router/router-guards.ts 对称实现,去掉 keepAlive 逻辑 + * (PC 端无 keepAlive 需求)。 + */ +export function createPcRouterGuards(router: Router) { + router.afterEach((to) => { + // 设置每个页面的 title + const title = to?.meta?.title as string | undefined + if (title) { + document.title = title + } + }) +}