@@ -64,6 +64,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
6464 private refCache : RefCache = new RefCache ( ) ;
6565 private isInitialPage : boolean = true ;
6666 private detachedLoaderFactory : ComponentFactory < DetachedLoader > ;
67+ private itemsToDestroy : CacheItem [ ] = [ ] ;
6768
6869 private currentActivatedComp : ComponentRef < any > ;
6970 private currentActivatedRoute : ActivatedRoute ;
@@ -132,7 +133,12 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
132133
133134 private clearRefCache ( ) {
134135 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 ( ) ) ;
136142 }
137143 }
138144 private destroyCacheItem ( poppedItem : CacheItem ) {
@@ -242,7 +248,10 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
242248 // Add it to the new page
243249 page . content = componentView ;
244250
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 ) => {
246255 if ( args . isBackNavigation ) {
247256 this . locationStrategy . _beginBackPageNavigation ( ) ;
248257 this . locationStrategy . back ( ) ;
0 commit comments