routes 配置中的每个路由对象为 路由记录;
定义路由的时候可以配置 meta 字段:(router.js)
const routes = [{
path: '/',
component: TheLogin,
meta:{
title:'登录'
}
},
{
path: '/register2',
name: 'reg',
component: TheRegister2,
meta:{
title:'注册'
}
},
children: [{
path: 'student',
component: TheStudent,
name: 'student'
},
{
path: 'classmanager',
component: ClassManager,
name: 'classmanager'
},
{
path: 'schoolmanager',
component: SchoolManager,
name: 'schoolmanager'
}
]
},
]
每个守卫方法接收三个参数:
to: Route: 即将要进入的目标 路由对象
from: Route: 当前导航正要离开的路由
next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
router.beforeEach((to,from,next)=>{
if(to.meta.title){
document.title=to.meta.title
}
next()
})