全局路由
1. 全局前置守卫,router.beforeEach,
to:要进入的目标对象;
form:当前导航离开的路由对象
next fn:必须执行,跳转到一个新地址
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
router.beforeEach((to, form, next) => {
console.log(to);
console.log(form);
next();
//验证token,只有token存在的时候才能跳转到内容页
// let token=localStorage.getItem('token');
// if(token||to.path==='/login'){
// next();
// }else{
// next('/login')
// }
})
2. 全局后置守卫router.afterEach
router.afterEach((to, form) => {
console.log(to);
console.log(form);
})
3. router.beforeResolve
在组件被解析之后调用
`
路由独享的守卫
beforeEnter