Skip to content

Commit 448412a

Browse files
buuhuusis0k0
authored andcommitted
fix: asynchronously destroy items evicted on clearHistory navigation (#847)
fixes #829
1 parent 7b6bf4f commit 448412a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Diff for: nativescript-angular/router/page-router-outlet.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)