Narutocc / Vue

:smirk_cat:Vue is a progressive framework for building user interfaces. Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.
1 stars 0 forks source link

路由钩子 #98

Open Narutocc opened 3 years ago

Narutocc commented 3 years ago

有多种方式可以在路由导航发生时执行钩子:全局的、单个路由独享的、或者组件级的。

1. 全局钩子

router.beforeEach((to, from, next) => {})

router.afterEach((to, from) => {}) // after 钩子没有 next 方法,不能改变导航

2. 某个路由独享的钩子

beforeEnter: (to, from, next) => {})

3. 组件内的钩子

beforeRouteEnter:在路由进入前的钩子函数

beforeRouteLeave:在路由离开前的钩子函数

beforeRouteUpdate