Skip to content

Commit 8925ce1

Browse files
committed
[docs] improve docs on how hooks work (close #259)
1 parent 15f0689 commit 8925ce1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/en/api/before-each.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Add a global before hook to the router, which will be called before every route
44

55
You can add multiple global before hooks to the same router. These hooks will be called in the order of creation. Since hooks can be resolved asynchronously, the next hook won't be called until the previous one resolves.
66

7+
Global before hooks are resolved following the same [Hook resolution rules](../pipeline/hooks.html#hook-resolution-rules).
8+
79
### Arguments
810

911
- `hook {Function}`

docs/en/route.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ When `/a` is matched, `$route.auth` will be `true`. This allows us to perform au
4545

4646
``` js
4747
router.beforeEach(function (transition) {
48-
if (transition.to.auth) {
49-
// do authentication...
48+
if (transition.to.auth && !authenticated) {
49+
transition.redirect('/login')
50+
} else {
51+
transition.next()
5052
}
5153
})
5254
```
5355

56+
> See [API](api/before-each.md) for how the `beforeEach` hook works.
57+
5458
When a nested route is matched, all custom fields will be merged on to the same `$route` object. When a sub route and a parent route has the same custom field, the sub route's value will overwrite the parent's.
5559

5660
### Using in Templates

0 commit comments

Comments
 (0)