首先,需要在 router.js 路由表找到想要设置路由对象,比如:
{
path: "/index",
name: "index",
meta: {
title: "自定义标题"
},
component: resolve => require(["@/components/index"], resolve)
}
然后,在 main.js里面添加以下代码即可:
import router from './router'
// 路由发生变化修改页面title
router.beforeEach ((to,from,next) => {
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
网友评论