Skip to content

Commit d583a3f

Browse files
committed
fix keep-alive child view save logic
1 parent 10e534d commit d583a3f

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/pipeline.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function deactivate (view, transition, next) {
108108
export function activate (view, transition, depth, cb, reuse) {
109109
let handler = transition.activateQueue[depth]
110110
if (!handler) {
111-
// fix 1.0.0-alpha.3 compat
111+
saveChildView(view)
112112
if (view._bound) {
113113
view.setComponent(null)
114114
}
@@ -138,16 +138,12 @@ export function activate (view, transition, depth, cb, reuse) {
138138
component = view.childVM
139139
component.$loadingRouteData = loading
140140
} else {
141+
saveChildView(view)
142+
141143
// unbuild current component. this step also destroys
142144
// and removes all nested child views.
143145
view.unbuild(true)
144146

145-
// handle keep-alive.
146-
// cache the child view on the kept-alive child vm.
147-
if (view.keepAlive && view.childVM && view.childView) {
148-
view.childVM._keepAliveRouterView = view.childView
149-
}
150-
151147
// build the new component. this will also create the
152148
// direct child view of the current one. it will register
153149
// itself as view.childView.
@@ -300,6 +296,26 @@ function loadData (component, transition, hook, cb, cleanup) {
300296
})
301297
}
302298

303-
function isPlainObject (obj) {
304-
return Object.prototype.toString.call(obj) === '[object Object]'
299+
/**
300+
* Save the child view for a kept-alive view so that
301+
* we can restore it when it is switched back to.
302+
*
303+
* @param {Directive} view
304+
*/
305+
306+
function saveChildView (view) {
307+
if (view.keepAlive && view.childVM && view.childView) {
308+
view.childVM._keepAliveRouterView = view.childView
309+
}
310+
view.childView = null
311+
}
312+
313+
/**
314+
* Check plain object.
315+
*
316+
* @param {*} val
317+
*/
318+
319+
function isPlainObject (val) {
320+
return Object.prototype.toString.call(val) === '[object Object]'
305321
}

0 commit comments

Comments
 (0)