refactor(router): make RouterLink and RouterLinkWithHref create url in a similar way
This commit is contained in:
parent
bb9dfbc578
commit
93f323cfa2
|
@ -128,8 +128,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
|
||||||
// the url displayed on the anchor element.
|
// the url displayed on the anchor element.
|
||||||
@HostBinding() href: string;
|
@HostBinding() href: string;
|
||||||
|
|
||||||
urlTree: UrlTree;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router, private route: ActivatedRoute,
|
private router: Router, private route: ActivatedRoute,
|
||||||
private locationStrategy: LocationStrategy) {
|
private locationStrategy: LocationStrategy) {
|
||||||
|
@ -167,17 +165,17 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTargetUrlAndHref(): void {
|
private updateTargetUrlAndHref(): void {
|
||||||
this.urlTree = this.router.createUrlTree(this.commands, {
|
this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
|
||||||
|
}
|
||||||
|
|
||||||
|
get urlTree(): UrlTree {
|
||||||
|
return this.router.createUrlTree(this.commands, {
|
||||||
relativeTo: this.route,
|
relativeTo: this.route,
|
||||||
queryParams: this.queryParams,
|
queryParams: this.queryParams,
|
||||||
fragment: this.fragment,
|
fragment: this.fragment,
|
||||||
preserveQueryParams: toBool(this.preserveQueryParams),
|
preserveQueryParams: toBool(this.preserveQueryParams),
|
||||||
preserveFragment: toBool(this.preserveFragment)
|
preserveFragment: toBool(this.preserveFragment)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.urlTree) {
|
|
||||||
this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue