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