一、全局守卫
(工作中经常用主要是前置守卫 用来做路由拦截 拦截权限 拦截是否登录)
前置守卫 (如果在单独文件中记得引入 路由文件)
router.beforeEach((to,from,next)=>{
})
后置守卫
router.afterEach((to,from)=>{
})
二、 路由独享守卫
{
path:'/路径',
component:组件名,
name:'',
alias:'别名',
beforeEnter:(to,from,next)=>{
}
}
三、组件路由守卫
beforeRouteEnter(to,from,next){
//进入组件的拦截
//这个时候不存在this 因为组件生命周期还没有开始
}
beforeRouteUpdate(to,from,next){
//组件更新的拦截
//存在this
}
beforeRouteLeave(to,from,next){
//离开组件的拦截
//存在this
}