to 要去的路由地址
from从哪个地址来
next() 可以跳转 next('url')跳转到指定地址 false不允许跳转
1.全局前置路由守卫
router.beforeEach(function(to,from,next){
next()
}
2.全局后置路由守卫
router.afterEach(function(to,from){
next()
}
3.独享守卫
beforeEach((to, from, next) => {
// must call `next`
console.log(to);
next() });
//组件内守卫-进入之前 beforeRouteEnter(to,from,next){ console.log('路由创建之前');//获取不到信息 console.log(from); next() }, beforeCreate(){ console.log('创建之前'); }, //组件内守卫-离开之前 beforeRouteLeave(to,from,next){ console.log('路由离开之前'); console.log(to); next() }, beforeDestroy(){ console.log('毁灭'); }, 组件内守卫-路由更新 (子路由或者路由发生变化) beforeRouteUpdate(to,from,next){ console.log(from); next() } 跟watch异曲同工