File tree 2 files changed +20
-12
lines changed
2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -45,17 +45,12 @@ export default {
45
45
46
46
const component = cache [ name ] = matched . components [ name ]
47
47
48
- // inject instance registration hooks
49
- const hooks = data . hook || ( data . hook = { } )
50
- hooks . init = vnode => {
51
- matched . instances [ name ] = vnode . componentInstance
52
- }
53
- hooks . prepatch = ( oldVnode , vnode ) => {
54
- matched . instances [ name ] = vnode . componentInstance
55
- }
56
- hooks . destroy = vnode => {
57
- if ( matched . instances [ name ] === vnode . componentInstance ) {
58
- matched . instances [ name ] = undefined
48
+ // attach instance registration hook
49
+ // this will be called in the instance's injected lifecycle hooks
50
+ data . registerRouteInstance = ( vm , val ) => {
51
+ // val could be undefined for unregistration
52
+ if ( matched . instances [ name ] !== vm ) {
53
+ matched . instances [ name ] = val
59
54
}
60
55
}
61
56
Original file line number Diff line number Diff line change @@ -17,13 +17,26 @@ export function install (Vue) {
17
17
get ( ) { return this . $root . _route }
18
18
} )
19
19
20
+ const isDef = v => v !== undefined
21
+
22
+ const registerInstance = ( vm , callVal ) => {
23
+ let i = vm . $options . _parentVnode
24
+ if ( isDef ( i ) && isDef ( i = i . data ) && isDef ( i = i . registerRouteInstance ) ) {
25
+ i ( vm , callVal )
26
+ }
27
+ }
28
+
20
29
Vue . mixin ( {
21
30
beforeCreate ( ) {
22
- if ( this . $options . router ) {
31
+ if ( isDef ( this . $options . router ) ) {
23
32
this . _router = this . $options . router
24
33
this . _router . init ( this )
25
34
Vue . util . defineReactive ( this , '_route' , this . _router . history . current )
26
35
}
36
+ registerInstance ( this , this )
37
+ } ,
38
+ destroyed ( ) {
39
+ registerInstance ( this )
27
40
}
28
41
} )
29
42
You can’t perform that action at this time.
0 commit comments