每个页面配置新的页面title
设置 title 的方式是采用 js 给 document.title 赋值。
可以在路由守卫的地方给每个页面设置 title。
import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeIndex from '@/pages/home/index.vue'
Vue.use(VueRouter)
const router = new VueRouter({
mode: 'history',
base: import.meta.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
meta: { title: 'xxxxxx' },
component: HomeIndex
},
{
path: '/activity',
name: 'activity',
meta: { title: 'xxxxxxx' },
component: () => import('@/pages/activity/index.vue')
}
]
})
router.beforeEach((to, from, next) => {
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
export default router
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
上次更新: 2023/12/16, 09:22:46