From 8bedc2d14fccc8d6c1ea18151bda7ce7c87fddae Mon Sep 17 00:00:00 2001 From: Bellal Mohamed Date: Thu, 27 Aug 2020 08:03:14 +0200 Subject: [PATCH 1/2] fix(router): page navigation bug if there's not outlet for frame after clearing history (#2233) --- .../router/ns-location-strategy.ts | 2 +- .../router/ns-router-link-active.ts | 12 ++--- nativescript-angular/router/ns-router-link.ts | 47 +++++++++---------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/nativescript-angular/router/ns-location-strategy.ts b/nativescript-angular/router/ns-location-strategy.ts index 99c3b8a3c..4c0088c8b 100644 --- a/nativescript-angular/router/ns-location-strategy.ts +++ b/nativescript-angular/router/ns-location-strategy.ts @@ -342,7 +342,7 @@ export class NSLocationStrategy extends LocationStrategy { NativeScriptDebug.routerLog('NSLocationStrategy._beginPageNavigation()'); } - this.currentOutlet = this.getOutletByFrame(frame); + this.currentOutlet = this.getOutletByFrame(frame) || this.currentOutlet; const lastState = this.currentOutlet.peekState(); if (lastState) { diff --git a/nativescript-angular/router/ns-router-link-active.ts b/nativescript-angular/router/ns-router-link-active.ts index e9a2fa504..b00a35679 100644 --- a/nativescript-angular/router/ns-router-link-active.ts +++ b/nativescript-angular/router/ns-router-link-active.ts @@ -105,12 +105,12 @@ export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentIni const currentUrlTree = this.router.parseUrl(this.router.url); const isActiveLinks = this.reduceList(currentUrlTree, this.links); this.classes.forEach((c) => { - if (isActiveLinks) { - this.renderer.addClass(this.element.nativeElement, c); - } else { - this.renderer.removeClass(this.element.nativeElement, c); - } - }); + if (isActiveLinks) { + this.renderer.addClass(this.element.nativeElement, c); + } else { + this.renderer.removeClass(this.element.nativeElement, c); + } + }); } Promise.resolve(hasActiveLinks).then((active) => (this.active = active)); } diff --git a/nativescript-angular/router/ns-router-link.ts b/nativescript-angular/router/ns-router-link.ts index b380d7178..23aa97bac 100644 --- a/nativescript-angular/router/ns-router-link.ts +++ b/nativescript-angular/router/ns-router-link.ts @@ -52,30 +52,29 @@ export class NSRouterLink { private commands: any[] = []; - constructor(private ngZone: NgZone, private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute, private el: ElementRef) { - } - - ngAfterViewInit() { - this.el.nativeElement.on('tap', () => { - this.ngZone.run(() => { - if (NativeScriptDebug.isLogEnabled()) { - NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`); - } - - const extras = this.getExtras(); - // this.navigator.navigateByUrl(this.urlTree, extras); - this.navigator.navigate(this.commands, { - ...extras, - relativeTo: this.route, - queryParams: this.queryParams, - fragment: this.fragment, - preserveQueryParams: attrBoolValue(this.preserveQueryParams), - queryParamsHandling: this.queryParamsHandling, - preserveFragment: attrBoolValue(this.preserveFragment), - }); - }); - }); - } + constructor(private ngZone: NgZone, private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute, private el: ElementRef) {} + + ngAfterViewInit() { + this.el.nativeElement.on('tap', () => { + this.ngZone.run(() => { + if (NativeScriptDebug.isLogEnabled()) { + NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`); + } + + const extras = this.getExtras(); + // this.navigator.navigateByUrl(this.urlTree, extras); + this.navigator.navigate(this.commands, { + ...extras, + relativeTo: this.route, + queryParams: this.queryParams, + fragment: this.fragment, + preserveQueryParams: attrBoolValue(this.preserveQueryParams), + queryParamsHandling: this.queryParamsHandling, + preserveFragment: attrBoolValue(this.preserveFragment), + }); + }); + }); + } @Input('nsRouterLink') set params(data: any[] | string) { From 737a5dfe8f72907870b783c736bedccc9958d602 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Thu, 27 Aug 2020 08:13:29 -0700 Subject: [PATCH 2/2] chore(release): 10.0.3 --- CHANGELOG.md | 9 +++++++++ nativescript-angular/package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5610f3662..ee258f56c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [10.0.3](https://github.com/NativeScript/nativescript-angular/compare/10.0.2...10.0.3) (2020-08-27) + + +### Bug Fixes + +* **router:** page navigation bug if there's not outlet for frame after clearing history ([#2233](https://github.com/NativeScript/nativescript-angular/issues/2233)) ([8bedc2d](https://github.com/NativeScript/nativescript-angular/commit/8bedc2d14fccc8d6c1ea18151bda7ce7c87fddae)) + + + ## [10.0.2](https://github.com/NativeScript/nativescript-angular/compare/10.0.1...10.0.2) (2020-08-19) diff --git a/nativescript-angular/package.json b/nativescript-angular/package.json index ab4d7f23e..067cdbc0f 100644 --- a/nativescript-angular/package.json +++ b/nativescript-angular/package.json @@ -1,6 +1,6 @@ { "name": "@nativescript/angular", - "version": "10.0.2", + "version": "10.0.3", "description": "An Angular renderer that lets you build mobile apps with NativeScript.", "homepage": "https://www.nativescript.org/", "bugs": "https://github.com/NativeScript/nativescript-angular/issues",