fix(router): 聚合支付页浏览器标题不切换

- mobile: Aggregate 父级补 meta.title,子路由(entry/unsupported/各环境页)自动继承
- pc: PcAggregate/PcAggregateUnsupported 补 meta.title
- pc: 新增 router-guards 挂载 afterEach 切换 document.title(原 PC 端全站缺守卫,顺带修复)
This commit is contained in:
bootx
2026-07-20 15:52:11 +08:00
parent 8138d93f62
commit dc196aca8f
3 changed files with 30 additions and 0 deletions

View File

@@ -57,6 +57,10 @@ const routeModuleList: Array<RouteRecordRaw> = [
path: RoutePath.AGGREGATE_GROUP,
name: 'Aggregate',
component: Layout,
// 父级声明 title子路由unsupported / 各环境页 / entry由 vue-router 的 to.meta 合并自动继承
meta: {
title: '收银台',
},
children: [
// 非宿主提示:静态 path 段
{

View File

@@ -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 }

View File

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