@@ -137,20 +137,11 @@ export function activate (view, transition, depth, cb, reuse) {
137
137
// unbuild current component. this step also destroys
138
138
// and removes all nested child views.
139
139
view . unbuild ( true )
140
+
140
141
// 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
154
145
}
155
146
156
147
// build the new component. this will also create the
@@ -171,12 +162,10 @@ export function activate (view, transition, depth, cb, reuse) {
171
162
// and also properly update current view's child view.
172
163
if ( view . keepAlive ) {
173
164
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
180
169
}
181
170
}
182
171
}
0 commit comments