Skip to content

Commit 8bedc2d

Browse files
fix(router): page navigation bug if there's not outlet for frame after clearing history (#2233)
1 parent 1c7ba3c commit 8bedc2d

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

Diff for: nativescript-angular/router/ns-location-strategy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class NSLocationStrategy extends LocationStrategy {
342342
NativeScriptDebug.routerLog('NSLocationStrategy._beginPageNavigation()');
343343
}
344344

345-
this.currentOutlet = this.getOutletByFrame(frame);
345+
this.currentOutlet = this.getOutletByFrame(frame) || this.currentOutlet;
346346
const lastState = this.currentOutlet.peekState();
347347

348348
if (lastState) {

Diff for: nativescript-angular/router/ns-router-link-active.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentIni
105105
const currentUrlTree = this.router.parseUrl(this.router.url);
106106
const isActiveLinks = this.reduceList(currentUrlTree, this.links);
107107
this.classes.forEach((c) => {
108-
if (isActiveLinks) {
109-
this.renderer.addClass(this.element.nativeElement, c);
110-
} else {
111-
this.renderer.removeClass(this.element.nativeElement, c);
112-
}
113-
});
108+
if (isActiveLinks) {
109+
this.renderer.addClass(this.element.nativeElement, c);
110+
} else {
111+
this.renderer.removeClass(this.element.nativeElement, c);
112+
}
113+
});
114114
}
115115
Promise.resolve(hasActiveLinks).then((active) => (this.active = active));
116116
}

Diff for: nativescript-angular/router/ns-router-link.ts

+23-24
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,29 @@ export class NSRouterLink {
5252

5353
private commands: any[] = [];
5454

55-
constructor(private ngZone: NgZone, private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute, private el: ElementRef) {
56-
}
57-
58-
ngAfterViewInit() {
59-
this.el.nativeElement.on('tap', () => {
60-
this.ngZone.run(() => {
61-
if (NativeScriptDebug.isLogEnabled()) {
62-
NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`);
63-
}
64-
65-
const extras = this.getExtras();
66-
// this.navigator.navigateByUrl(this.urlTree, extras);
67-
this.navigator.navigate(this.commands, {
68-
...extras,
69-
relativeTo: this.route,
70-
queryParams: this.queryParams,
71-
fragment: this.fragment,
72-
preserveQueryParams: attrBoolValue(this.preserveQueryParams),
73-
queryParamsHandling: this.queryParamsHandling,
74-
preserveFragment: attrBoolValue(this.preserveFragment),
75-
});
76-
});
77-
});
78-
}
55+
constructor(private ngZone: NgZone, private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute, private el: ElementRef) {}
56+
57+
ngAfterViewInit() {
58+
this.el.nativeElement.on('tap', () => {
59+
this.ngZone.run(() => {
60+
if (NativeScriptDebug.isLogEnabled()) {
61+
NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`);
62+
}
63+
64+
const extras = this.getExtras();
65+
// this.navigator.navigateByUrl(this.urlTree, extras);
66+
this.navigator.navigate(this.commands, {
67+
...extras,
68+
relativeTo: this.route,
69+
queryParams: this.queryParams,
70+
fragment: this.fragment,
71+
preserveQueryParams: attrBoolValue(this.preserveQueryParams),
72+
queryParamsHandling: this.queryParamsHandling,
73+
preserveFragment: attrBoolValue(this.preserveFragment),
74+
});
75+
});
76+
});
77+
}
7978

8079
@Input('nsRouterLink')
8180
set params(data: any[] | string) {

0 commit comments

Comments
 (0)