fix(router): add baseUrl to relative paths, but not absolute.
Closes #1783
This commit is contained in:
parent
7f976381d5
commit
a574154108
4
modules/angular2/src/router/location.js
vendored
4
modules/angular2/src/router/location.js
vendored
@ -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() {
|
||||||
|
13
modules/angular2/test/router/location_spec.js
vendored
13
modules/angular2/test/router/location_spec.js
vendored
@ -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) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user