什么是路由守卫?
- 路由在真正跳转前, 会执行一次beforeEach函数, 调用next()则跳转, 也可以通过next()强制修改要跳转的路由
// 添加全局路由守卫
router.beforeEach((to, from, next) => {
console.log(to);
console.log(from);
next()
})
- next:是一个函数,必须调用才能跳转页面
- to:表示跳转的目标路由对象
- from:表示跳转前的对象
- next(false):禁止跳转