fix(router): router link should navigate to non-base Url.

While still displaying full base + custom part of url in the href.
This commit is contained in:
Rado Kirov
2015-05-19 23:14:10 -07:00
parent 826af401a9
commit c45283216f
3 changed files with 70 additions and 26 deletions

View File

@ -45,7 +45,8 @@ export class SpyLocation extends SpyObject {
}
go(url:string) {
if (this._path === url) {
url = this.normalizeAbsolutely(url);
if (this._path == url) {
return;
}
this._path = url;

View File

@ -43,7 +43,10 @@ export class RouterLink {
_params:StringMap<string, string>;
_router:Router;
_location:Location;
_href:string;
// the url displayed on the anchor element.
_visibleHref: string;
// the url passed to the router navigation.
_navigationHref: string;
constructor(elementRef:ElementRef, router:Router, location:Location) {
this._domEl = elementRef.domElement;
@ -52,7 +55,7 @@ export class RouterLink {
this._params = StringMapWrapper.create();
DOM.on(this._domEl, 'click', (evt) => {
evt.preventDefault();
this._router.navigate(this._href);
this._router.navigate(this._navigationHref);
});
}
@ -66,11 +69,11 @@ export class RouterLink {
onAllChangesDone(): void {
if (isPresent(this._route) && isPresent(this._params)) {
var newHref = this._router.generate(this._route, this._params);
this._href = this._location.normalizeAbsolutely(newHref);
this._navigationHref = this._router.generate(this._route, this._params);
this._visibleHref = this._location.normalizeAbsolutely(this._navigationHref);
// Keeping the link on the element to support contextual menu `copy link`
// and other in-browser affordances.
DOM.setAttribute(this._domEl, 'href', this._href);
DOM.setAttribute(this._domEl, 'href', this._visibleHref);
}
}
}