Skip to content

Commit cd27d50

Browse files
committed
copy custom route config fields onto the $route object
1 parent 7e964e2 commit cd27d50

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/route.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const internalKeysRE = /^(component|subRoutes)$/
2+
13
/**
24
* Route Context Object
35
*
@@ -8,17 +10,26 @@
810
export default class Route {
911

1012
constructor (path, router) {
11-
this.path = path
12-
this.router = router
13-
1413
let matched = router._recognizer.recognize(path)
1514

15+
// copy all custom fields from route configs
16+
if (matched) {
17+
[].forEach.call(matched, match => {
18+
for (let key in match.handler) {
19+
if (!internalKeysRE.test(key)) {
20+
this[key] = match.handler[key]
21+
}
22+
}
23+
})
24+
}
25+
26+
this.path = path
27+
this.router = router
1628
this.query = matched
1729
? matched.queryParams
1830
: {}
19-
2031
this.params = matched
21-
? [].reduce.call(matched, function (prev, cur) {
32+
? [].reduce.call(matched, (prev, cur) => {
2233
if (cur.params) {
2334
for (let key in cur.params) {
2435
prev[key] = cur.params[key]

src/router/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default function (Vue, Router) {
44

55
/**
66
* Register a map of top-level paths.
7+
*
8+
* @param {Object} map
79
*/
810

911
Router.prototype.map = function (map) {

0 commit comments

Comments
 (0)