Skip to content

Commit 79d0001

Browse files
committed
add getMatchedComponents
1 parent cf38992 commit 79d0001

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.flowconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99

1010
[libs]
1111
flow
12+
13+
[options]
14+
unsafe.enable_getters_and_setters=true

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default class VueRouter {
3838
this.mode = mode
3939
}
4040

41+
get currentRoute (): ?Route {
42+
return this.history && this.history.current
43+
}
44+
4145
init (app: any /* Vue component instance */) {
4246
assert(
4347
install.installed,
@@ -103,6 +107,17 @@ export default class VueRouter {
103107
this.app._route = route
104108
}
105109
}
110+
111+
getMatchedComponents (): Array<any> {
112+
if (!this.currentRoute) {
113+
return []
114+
}
115+
return [].concat.apply([], this.currentRoute.matched.map(m => {
116+
return Object.keys(m.components).map(key => {
117+
return m.components[key]
118+
})
119+
}))
120+
}
106121
}
107122

108123
VueRouter.install = install

0 commit comments

Comments
 (0)