@@ -64,6 +64,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
64
64
private refCache : RefCache = new RefCache ( ) ;
65
65
private isInitialPage : boolean = true ;
66
66
private detachedLoaderFactory : ComponentFactory < DetachedLoader > ;
67
+ private itemsToDestroy : CacheItem [ ] = [ ] ;
67
68
68
69
private currentActivatedComp : ComponentRef < any > ;
69
70
private currentActivatedRoute : ActivatedRoute ;
@@ -132,7 +133,12 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
132
133
133
134
private clearRefCache ( ) {
134
135
while ( this . refCache . length > 0 ) {
135
- this . destroyCacheItem ( this . refCache . pop ( ) ) ;
136
+ this . itemsToDestroy . push ( this . refCache . pop ( ) ) ;
137
+ }
138
+ }
139
+ private destroyQueuedCacheItems ( ) {
140
+ while ( this . itemsToDestroy . length > 0 ) {
141
+ this . destroyCacheItem ( this . itemsToDestroy . pop ( ) ) ;
136
142
}
137
143
}
138
144
private destroyCacheItem ( poppedItem : CacheItem ) {
@@ -242,7 +248,10 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
242
248
// Add it to the new page
243
249
page . content = componentView ;
244
250
245
- page . on ( "navigatedFrom" , ( < any > global ) . Zone . current . wrap ( ( args : NavigatedData ) => {
251
+ page . on ( Page . navigatedToEvent , ( ) => setTimeout ( ( ) => {
252
+ this . destroyQueuedCacheItems ( ) ;
253
+ } ) ) ;
254
+ page . on ( Page . navigatedFromEvent , ( < any > global ) . Zone . current . wrap ( ( args : NavigatedData ) => {
246
255
if ( args . isBackNavigation ) {
247
256
this . locationStrategy . _beginBackPageNavigation ( ) ;
248
257
this . locationStrategy . back ( ) ;
0 commit comments