Skip to content

Commit 1357584

Browse files
committed
docs: custom fields
1 parent c50c2fb commit 1357584

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/en/route.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ A route object exposes the following properties:
2020

2121
The router instance that is managing this route (and its owner component).
2222

23+
### Custom Fields
24+
25+
In addition to the built-in properties, custom fields defined in the route config will also be merged on to the route object. For example:
26+
27+
``` js
28+
router.map({
29+
'/a': {
30+
component: { ... },
31+
auth: true
32+
}
33+
})
34+
```
35+
36+
When `/a` is matched, `$route.auth` will be `true`. This allows us to perform authentication checks in global hooks:
37+
38+
``` js
39+
router.beforeEach(function (transition) {
40+
if (transition.to.auth) {
41+
// do authentication...
42+
}
43+
})
44+
```
45+
46+
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.
47+
2348
### Using in Templates
2449

2550
You can directly bind to the `$route` object inside your component templates. For example:

0 commit comments

Comments
 (0)