在路由表中写标题信息
如下文所示
1 2 3 4 5 6 7 8 9 | const routes = [ { path: '/', name: 'home', component: HomeView, meta: { title: "主页" } }] |
设置Navigation Guards
官方文档:Navigation Guards | Vue Router (vuejs.org)
在引入router后,创建引用并mount应用前,使用如下代码以设置在URL变化时查找路由表中对应的路由是否设置了标题,若设置了标题则将当前页面的标题改为预设的标题。
1 2 3 4 5 6 7 | router.beforeEach((to, from, next) => { /* 路由发生变化修改页面title */ if (to.meta.title) { document.title = to.meta.title } next() }) |
此外你可以在to.meta.title后加上此站点的名字等
发表回复