Skip to content

Commit 4174ac3

Browse files
committed
handle keep-alive with new strategy
1 parent 2d2356c commit 4174ac3

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/pipeline.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,11 @@ export function activate (view, transition, depth, cb, reuse) {
137137
// unbuild current component. this step also destroys
138138
// and removes all nested child views.
139139
view.unbuild(true)
140+
140141
// handle keep-alive.
141-
// if the view has keep-alive, the child vm is not actually
142-
// destroyed - its nested views will still be in router's
143-
// view list. We need to removed these child views and
144-
// cache them on the child vm.
145-
if (view.keepAlive) {
146-
let views = transition.router._views
147-
let i = views.indexOf(view)
148-
if (i > 0) {
149-
transition.router._views = views.slice(i)
150-
if (view.childVM) {
151-
view.childVM._routerViews = views.slice(0, i)
152-
}
153-
}
142+
// cache the child view on the kept-alive child vm.
143+
if (view.keepAlive && view.childVM && view.childView) {
144+
view.childVM._keepAliveRouterView = view.childView
154145
}
155146

156147
// build the new component. this will also create the
@@ -171,12 +162,10 @@ export function activate (view, transition, depth, cb, reuse) {
171162
// and also properly update current view's child view.
172163
if (view.keepAlive) {
173164
component.$loadingRouteData = loading
174-
let cachedViews = component._routerViews
175-
if (cachedViews) {
176-
transition.router._views = cachedViews.concat(transition.router._views)
177-
view.childView = cachedViews[cachedViews.length - 1]
178-
view.childView.parentView = view
179-
component._routerViews = null
165+
let cachedChildView = component._keepAliveRouterView
166+
if (cachedChildView) {
167+
view.childView = cachedChildView
168+
component._keepAliveRouterView = null
180169
}
181170
}
182171
}

0 commit comments

Comments
 (0)