router.beforeEach是一个全局前置守卫,用于在路由导航触发前进行一些权限校验或提示。
示例
main.js
//Guard
router.beforeEach((to, from, next) => {
console.log('Global beforeEach');
console.log(to, from);
//next(false); //阻止跳转路由
next(); //允许跳转路由
// if (to.name === 'team-members'){
// next();
// }else{
// next({name: 'team-members', params: {teamId: 't2'}});
// }
});