Skip to content

Commit 13c0cdd

Browse files
committed
fix: properly handle urltree navigation
1 parent 16aa7b6 commit 13c0cdd

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

packages/angular/src/lib/legacy/router/ns-router-link.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,24 @@ export class NSRouterLink implements OnChanges, OnDestroy {
327327
}
328328

329329
const extras = this.getExtras();
330-
this.navigator.navigate(this.routerLinkInput() as any[], {
331-
...extras,
332-
// If the `relativeTo` input is not defined, we want to use `this.route`
333-
// by default.
334-
relativeTo: this._relativeTo() !== undefined ? this._relativeTo() : this.route,
335-
queryParams: this._queryParams(),
336-
fragment: this._fragment(),
337-
queryParamsHandling: this._queryParamsHandling(),
338-
preserveFragment: this._preserveFragment(),
339-
});
330+
const routerLinkInput = this.routerLinkInput();
331+
332+
// When the input is a UrlTree, use navigateByUrl directly.
333+
// Otherwise, use navigate with commands array.
334+
if (isUrlTree(routerLinkInput)) {
335+
this.navigator.navigateByUrl(urlTree, extras);
336+
} else {
337+
this.navigator.navigate(routerLinkInput as any[], {
338+
...extras,
339+
// If the `relativeTo` input is not defined, we want to use `this.route`
340+
// by default.
341+
relativeTo: this._relativeTo() !== undefined ? this._relativeTo() : this.route,
342+
queryParams: this._queryParams(),
343+
fragment: this._fragment(),
344+
queryParamsHandling: this._queryParamsHandling(),
345+
preserveFragment: this._preserveFragment(),
346+
});
347+
}
340348
}
341349

342350
private getExtras(): NavigationExtras & NavigationOptions {

0 commit comments

Comments
 (0)