Skip to content

Commit f5e9fcf

Browse files
committed
docs for beforeRouteUpdate
1 parent 2eb95c5 commit f5e9fcf

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

docs/en/advanced/navigation-guards.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ These guards have the exact same signature as global before guards.
6464

6565
### In-Component Guards
6666

67-
Finally, you can directly define route navigation guards inside route components (the ones passed to the router configuration) with `beforeRouteEnter` and `beforeRouteLeave`:
67+
Finally, you can directly define route navigation guards inside route components (the ones passed to the router configuration) with the following options:
68+
69+
- `beforeRouteEnter`
70+
- `beforeRouteUpdate` (added in 2.2)
71+
- `beforeRouteLeave`
6872

6973
``` js
7074
const Foo = {
@@ -74,6 +78,14 @@ const Foo = {
7478
// does NOT have access to `this` component instance,
7579
// because it has not been created yet when this guard is called!
7680
},
81+
beforeRouteUpdate (to, from, next) {
82+
// called when the route that renders this component has changed,
83+
// but this component is reused in the new route.
84+
// For example, for a route with dynamic params /foo/:id, when we
85+
// navigate between /foo/1 and /foo/2, the same Foo component instance
86+
// will be reused, and this hook will be called when that happens.
87+
// has access to `this` component instance.
88+
},
7789
beforeRouteLeave (to, from, next) {
7890
// called when the route that renders this component is about to
7991
// be navigated away from.

docs/zh-cn/advanced/navigation-guards.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ const router = new VueRouter({
6565

6666
### 组件内的钩子
6767

68-
最后,你可以使用 `beforeRouteEnter``beforeRouteLeave`,在路由组件内直接定义路由导航钩子,
68+
最后,你可以在路由组件内直接定义以下路由导航钩子:
69+
70+
- `beforeRouteEnter`
71+
- `beforeRouteUpdate` (2.2 新增)
72+
- `beforeRouteLeave`
6973

7074
``` js
7175
const Foo = {
@@ -75,6 +79,12 @@ const Foo = {
7579
// 不!能!获取组件实例 `this`
7680
// 因为当钩子执行前,组件实例还没被创建
7781
},
82+
beforeRouteUpdate (to, from, next) {
83+
// 在当前路由改变,但是改组件被复用时调用
84+
// 举例来说,对于一个带有动态参数的路径 /foo/:id,在 /foo/1 和 /foo/2 之间跳转的时候,
85+
// 由于会渲染同样的 Foo 组件,因此组件实例会被复用。而这个钩子就会在这个情况下被调用。
86+
// 可以访问组件实例 `this`
87+
},
7888
beforeRouteLeave (to, from, next) {
7989
// 导航离开该组件的对应路由时调用
8090
// 可以访问组件实例 `this`

0 commit comments

Comments
 (0)