You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/advanced/navigation-guards.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Remember that **params or query changes won't trigger enter/leave navigation gua
8
8
9
9
You can register global before guards using `router.beforeEach`:
10
10
11
-
```js
11
+
```js
12
12
constrouter=newVueRouter({ ... })
13
13
14
14
router.beforeEach((to, from, next) => {
@@ -34,7 +34,7 @@ Every guard function receives three arguments:
34
34
35
35
-**`next(error)`**: (2.4.0+) if the argument passed to `next` is an instance of `Error`, the navigation will be aborted and the error will be passed to callbacks registered via [`router.onError()`](../../api/#router-onerror).
36
36
37
-
**Make sure to always call the `next` function, otherwise the hook will never be resolved.**
37
+
**Make sure to always call the `next` function exactly one time in each navigation guard, otherwise the hook will never be resolved or produce errors.**
38
38
39
39
## Global Resolve Guards
40
40
@@ -44,7 +44,7 @@ You can register a global guard with `router.beforeResolve`. This is similar to
44
44
45
45
You can also register global after hooks, however unlike guards, these hooks do not get a `next` function and cannot affect the navigation:
You can define `beforeEnter` guards directly on a route's configuration object:
56
56
57
-
```js
57
+
```js
58
58
constrouter=newVueRouter({
59
59
routes: [
60
60
{
@@ -78,7 +78,7 @@ Finally, you can directly define route navigation guards inside route components
78
78
-`beforeRouteUpdate`
79
79
-`beforeRouteLeave`
80
80
81
-
```js
81
+
```js
82
82
constFoo= {
83
83
template:`...`,
84
84
beforeRouteEnter (to, from, next) {
@@ -106,7 +106,7 @@ The `beforeRouteEnter` guard does **NOT** have access to `this`, because the gua
106
106
107
107
However, you can access the instance by passing a callback to `next`. The callback will be called when the navigation is confirmed, and the component instance will be passed to the callback as the argument:
0 commit comments