一、全局钩子
router.beforeEach((to, from, next) => {
console.log('beforeEach');
});
router.afterEach((to, from) => {
console.log('beforeEach');
});
二、单个路由钩子
const router = new VueRouter({
routes: [{
path: '/index',
component: index,
beforeEnter(to, from, next) {},
beforeLeave(to, from, next) {}
}]
});
三、组件钩子
export default {
beforeRouteLeave(to, from, next) {},
beforeRouteEnter(to, from, next) {},
beforeRouteUpdate(to, from, next) {}
};