Skip to content

Commit 5c5b8ab

Browse files
committed
docs: next must be called only once
1 parent ca19a1f commit 5c5b8ab

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/guide/advanced/navigation-guards.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Remember that **params or query changes won't trigger enter/leave navigation gua
88

99
You can register global before guards using `router.beforeEach`:
1010

11-
``` js
11+
```js
1212
const router = new VueRouter({ ... })
1313

1414
router.beforeEach((to, from, next) => {
@@ -34,7 +34,7 @@ Every guard function receives three arguments:
3434

3535
- **`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).
3636

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.**
3838

3939
## Global Resolve Guards
4040

@@ -44,7 +44,7 @@ You can register a global guard with `router.beforeResolve`. This is similar to
4444

4545
You can also register global after hooks, however unlike guards, these hooks do not get a `next` function and cannot affect the navigation:
4646

47-
``` js
47+
```js
4848
router.afterEach((to, from) => {
4949
// ...
5050
})
@@ -54,7 +54,7 @@ router.afterEach((to, from) => {
5454

5555
You can define `beforeEnter` guards directly on a route's configuration object:
5656

57-
``` js
57+
```js
5858
const router = new VueRouter({
5959
routes: [
6060
{
@@ -78,7 +78,7 @@ Finally, you can directly define route navigation guards inside route components
7878
- `beforeRouteUpdate`
7979
- `beforeRouteLeave`
8080

81-
``` js
81+
```js
8282
const Foo = {
8383
template: `...`,
8484
beforeRouteEnter (to, from, next) {
@@ -106,7 +106,7 @@ The `beforeRouteEnter` guard does **NOT** have access to `this`, because the gua
106106

107107
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:
108108

109-
``` js
109+
```js
110110
beforeRouteEnter (to, from, next) {
111111
next(vm => {
112112
// access to component instance via `vm`

0 commit comments

Comments
 (0)