|
2 | 2 |
|
3 | 3 | As the name suggests, the navigation guards provided by `vue-router` are primarily used to guard navigations either by redirecting it or canceling it. There are a number of ways to hook into the route navigation process: globally, per-route, or in-component.
|
4 | 4 |
|
5 |
| -Remember **Params or queries changes won't trigger navigation guards**. Simply [watch the `$route` object](../essentials/dynamic-matching.md#reacting-to-params-changes) to react to those changes. |
| 5 | +Remember that **params or query changes won't trigger enter/leave navigation guards**. You can either [watch the `$route` object](../essentials/dynamic-matching.md#reacting-to-params-changes) to react to those changes, or use the `beforeRouteUpadte` in-component guard. |
6 | 6 |
|
7 | 7 | ### Global Guards
|
8 | 8 |
|
@@ -36,6 +36,14 @@ Every guard function receives three arguments:
|
36 | 36 |
|
37 | 37 | **Make sure to always call the `next` function, otherwise the hook will never be resolved.**
|
38 | 38 |
|
| 39 | +### Global Resolve Guards |
| 40 | + |
| 41 | +> New in 2.5.0 |
| 42 | +
|
| 43 | +In 2.5.0+ you can register a global guard with `router.onResolve`. This is similar to `router.beforeEach`, with the difference that resolve guards will be called right before the navigation is confirmed, **after all in-component guards and async route components are resolved**. |
| 44 | + |
| 45 | +### Global After Hooks |
| 46 | + |
39 | 47 | You can also register global after hooks, however unlike guards, these hooks do not get a `next` function and cannot affect the navigation:
|
40 | 48 |
|
41 | 49 | ``` js
|
@@ -109,3 +117,18 @@ beforeRouteEnter (to, from, next) {
|
109 | 117 | ```
|
110 | 118 |
|
111 | 119 | You can directly access `this` inside `beforeRouteLeave`. The leave guard is usually used to prevent the user from accidentally leaving the route with unsaved edits. The navigation can be canceled by calling `next(false)`.
|
| 120 | + |
| 121 | +### The Full Guard Resolution Flow |
| 122 | + |
| 123 | +1. Navigation triggered |
| 124 | +2. Call leave guards in deactivated components |
| 125 | +3. Call global `beforeEach` guards |
| 126 | +4. Call `beforeRouteUpdate` guards in reused components (2.2+) |
| 127 | +5. Call `beforeEnter` in route configs |
| 128 | +6. Resolve async route components |
| 129 | +7. Call `beforeRouteEnter` in activated components |
| 130 | +8. Call global `beforeResolve` guards (2.5+) |
| 131 | +9. Navigation confirmed. |
| 132 | +10. Call global `afterEach` hooks. |
| 133 | +11. DOM updates triggered. |
| 134 | +12. Call callbacks passed to `next` in `beforeRouteEnter` guards with instantiated instances. |
0 commit comments