本篇总结vue router中的守卫。
vue router提供的导航守卫主要用来通过跳转或取消的方式守卫导航。可分为以下几种:
1、全局的
2、单个路由独享的
3、或者组件级的
一、全局前置守卫
router.beforeEach((to,from,next)=>{
//to() 进入目标路由
//from() 离开的路由
//next() 下一个路由
//next({path:"/"}) 跳转到某个路由
next();
});
路由跳转前先执行。
二、全局后置钩子
router.