fix(router): add baseUrl to relative paths, but not absolute.
Closes #1783
This commit is contained in:
parent
7f976381d5
commit
a574154108
|
@ -35,8 +35,8 @@ export class Location {
|
|||
}
|
||||
|
||||
go(url:string) {
|
||||
url = this._stripBaseHref(url);
|
||||
this._browserLocation.pushState(null, '', url);
|
||||
var finalUrl = url[0] == '/' ? url : this._baseHref + '/' + url;
|
||||
this._browserLocation.pushState(null, '', finalUrl);
|
||||
}
|
||||
|
||||
forward() {
|
||||
|
|
|
@ -25,16 +25,21 @@ export function main() {
|
|||
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');
|
||||
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', () => {
|
||||
browserLocation.baseHref = '/my/app/index.html';
|
||||
location = new Location(browserLocation);
|
||||
location.go('/my/app/user/btford');
|
||||
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/user/btford');
|
||||
location.go('user/btford');
|
||||
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
|
||||
});
|
||||
|
||||
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {
|
||||
|
|
Loading…
Reference in New Issue