导航守卫
全局守卫
beforeEach( (to,from,next) => next() )
//全局前置守卫 页面解析前触发,每次路由跳转都会触发,可用于登录授权,配合meta路由元信息使用
beforeResolve( (to,from,next) => {} ) //全局解析守卫 页面解析完成后触发
afterEach( () => {} ) //全局后置守卫 页面全部完成后触发,没有参数
路由独享守卫
beforeEnter( (to,from,next) => {} ) //写在router中路由对象内,与path、name、component等并列
组件守卫
写在组件内
beforeRouteLeave //离开该组件时触发
beforeRouteEnter //进入该组件时触发,其内部next( vm => console.log(vm) )可获取即将跳转到的页面信息
beforeRouteUpdate //页面更新前触发 一般要和mounted配合使用
注:所有导航守卫函数中都必须设置有next()才能正常跳转页面;next(’/’)或next({path:’/’})或next({path:’/login’})跳转到一个指定不同的地址
几个导航守卫的触发顺序
beforeEach -> beforeEnter -> beforeRouteEnter -> beforeResolve -> afterEach