diff --git a/modules/angular2/src/router/location.js b/modules/angular2/src/router/location.js index ae5eb37055..2786c182f2 100644 --- a/modules/angular2/src/router/location.js +++ b/modules/angular2/src/router/location.js @@ -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() { diff --git a/modules/angular2/test/router/location_spec.js b/modules/angular2/test/router/location_spec.js index 4fef073f94..4913601a2a 100644 --- a/modules/angular2/test/router/location_spec.js +++ b/modules/angular2/test/router/location_spec.js @@ -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) => {