Skip to content

Commit

Permalink
fix(router): page navigation bug if there's not outlet for frame afte…
Browse files Browse the repository at this point in the history
…r clearing history (#2233)
  • Loading branch information
bellalMohamed authored Aug 27, 2020
1 parent 1c7ba3c commit 8bedc2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion nativescript-angular/router/ns-location-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions nativescript-angular/router/ns-router-link-active.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
47 changes: 23 additions & 24 deletions nativescript-angular/router/ns-router-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8bedc2d

Please sign in to comment.