From 93f323cfa2a62d1c41db6ae8ab321456872a8ccf Mon Sep 17 00:00:00 2001 From: vsavkin Date: Thu, 25 Aug 2016 07:27:22 -0700 Subject: [PATCH] refactor(router): make RouterLink and RouterLinkWithHref create url in a similar way --- .../@angular/router/src/directives/router_link.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/@angular/router/src/directives/router_link.ts b/modules/@angular/router/src/directives/router_link.ts index 742b4d2d18..d24ada3bcf 100644 --- a/modules/@angular/router/src/directives/router_link.ts +++ b/modules/@angular/router/src/directives/router_link.ts @@ -128,8 +128,6 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy { // the url displayed on the anchor element. @HostBinding() href: string; - urlTree: UrlTree; - constructor( private router: Router, private route: ActivatedRoute, private locationStrategy: LocationStrategy) { @@ -167,17 +165,17 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy { } 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, queryParams: this.queryParams, fragment: this.fragment, preserveQueryParams: toBool(this.preserveQueryParams), preserveFragment: toBool(this.preserveFragment) }); - - if (this.urlTree) { - this.href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.urlTree)); - } } }