在做单页面应用程序时,一般页面布局头尾两块都是固定在布局页面,中间为是路由入口。这时访问页面时头部标题不会变,该问题的解决方案如下:
通过采用组件内路由卫士(beforeRouterEnter、beforeRouterUpdate)与路由元信息(meta) 来实现更新头部标题信息。点击查看文档
beforeRouterEnter:第一次进入时调用。
beforeRouterUpdate:重复使用当前组件时调用。
效果图如下:
注意看页面标题与图标变换
路由元信息(meta)配置
在路由元信息中配置页面标题,通过组件内路由卫士获取
const router = newRouter({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: "help",
name: "help",
meta: {
title: "新手帮助"},
component: () => import('./views/Help.vue')
},
{
path: "page",
name: "page",
meta: {
title: "宝贝信息"},
component: () => imp