Skip to content

Commit a574154

Browse files
committed
fix(router): add baseUrl to relative paths, but not absolute.
Closes angular#1783
1 parent 7f97638 commit a574154

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

modules/angular2/src/router/location.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export class Location {
3535
}
3636

3737
go(url:string) {
38-
url = this._stripBaseHref(url);
39-
this._browserLocation.pushState(null, '', url);
38+
var finalUrl = url[0] == '/' ? url : this._baseHref + '/' + url;
39+
this._browserLocation.pushState(null, '', finalUrl);
4040
}
4141

4242
forward() {

modules/angular2/test/router/location_spec.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ export function main() {
2525
location = new Location(browserLocation);
2626
});
2727

28-
it('should normalize urls on navigate', () => {
28+
it('should normalize relative urls on navigate', () => {
29+
location.go('user/btford');
30+
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
31+
});
32+
33+
it('should not append urls with leading slash on navigate', () => {
2934
location.go('/my/app/user/btford');
30-
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/user/btford');
35+
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
3136
});
3237

3338
it('should remove index.html from base href', () => {
3439
browserLocation.baseHref = '/my/app/index.html';
3540
location = new Location(browserLocation);
36-
location.go('/my/app/user/btford');
37-
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/user/btford');
41+
location.go('user/btford');
42+
expect(browserLocation.spy('pushState')).toHaveBeenCalledWith(null, '', '/my/app/user/btford');
3843
});
3944

4045
it('should normalize urls on popstate', inject([AsyncTestCompleter], (async) => {

0 commit comments

Comments
 (0)