fix(router): add baseUrl to relative paths, but not absolute.

Closes #1783
This commit is contained in:
Rado Kirov 2015-05-11 14:49:55 -07:00
parent 7f976381d5
commit a574154108
2 changed files with 11 additions and 6 deletions

View File

@ -35,8 +35,8 @@ export class Location {
} }
go(url:string) { go(url:string) {
url = this._stripBaseHref(url); var finalUrl = url[0] == '/' ? url : this._baseHref + '/' + url;
this._browserLocation.pushState(null, '', url); this._browserLocation.pushState(null, '', finalUrl);
} }
forward() { forward() {

View File

@ -25,16 +25,21 @@ export function main() {
location = new Location(browserLocation); location = new Location(browserLocation);
}); });
it('should normalize urls on navigate', () => { it('should normalize relative urls on navigate', () => {
location.go('user/btford');
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
});
it('should not append urls with leading slash on navigate', () => {
location.go('/my/app/user/btford'); location.go('/my/app/user/btford');
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/user/btford'); expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
}); });
it('should remove index.html from base href', () => { it('should remove index.html from base href', () => {
browserLocation.baseHref = '/my/app/index.html'; browserLocation.baseHref = '/my/app/index.html';
location = new Location(browserLocation); location = new Location(browserLocation);
location.go('/my/app/user/btford'); location.go('user/btford');
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/user/btford'); expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
}); });
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => { it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {