Skip to content

Commit 93f323c

Browse files
vsavkinvicb
authored andcommitted
refactor(router): make RouterLink and RouterLinkWithHref create url in a similar way
1 parent bb9dfbc commit 93f323c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

modules/@angular/router/src/directives/router_link.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
128128
// the url displayed on the anchor element.
129129
@HostBinding() href: string;
130130

131-
urlTree: UrlTree;
132-
133131
constructor(
134132
private router: Router, private route: ActivatedRoute,
135133
private locationStrategy: LocationStrategy) {
@@ -167,17 +165,17 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
167165
}
168166

169167
private updateTargetUrlAndHref(): void {
170-
this.urlTree = this.router.createUrlTree(this.commands, {
168+
this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
169+
}
170+
171+
get urlTree(): UrlTree {
172+
return this.router.createUrlTree(this.commands, {
171173
relativeTo: this.route,
172174
queryParams: this.queryParams,
173175
fragment: this.fragment,
174176
preserveQueryParams: toBool(this.preserveQueryParams),
175177
preserveFragment: toBool(this.preserveFragment)
176178
});
177-
178-
if (this.urlTree) {
179-
this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree));
180-
}
181179
}
182180
}
183181

0 commit comments

Comments
 (0)