diff --git a/modules/angular2/src/router/location.ts b/modules/angular2/src/router/location.ts index 1c154d3dd0..5f1ae15a5f 100644 --- a/modules/angular2/src/router/location.ts +++ b/modules/angular2/src/router/location.ts @@ -21,7 +21,7 @@ export class Location { normalize(url: string): string { return this._stripBaseHref(stripIndexHtml(url)); } normalizeAbsolutely(url: string): string { - if (url[0] != '/') { + if (url.length > 0 && url[0] != '/') { url = '/' + url; } return this._addBaseHref(url); diff --git a/modules/angular2/test/router/location_spec.ts b/modules/angular2/test/router/location_spec.ts index b6fd0a0eed..4475d8e06f 100644 --- a/modules/angular2/test/router/location_spec.ts +++ b/modules/angular2/test/router/location_spec.ts @@ -35,6 +35,9 @@ export function main() { .toHaveBeenCalledWith(null, '', '/my/app/user/btford'); }); + it('should not prepend urls with starting slash when an empty URL is provided', + () => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.baseHref); }); + it('should not append urls with leading slash on navigate', () => { location.go('/my/app/user/btford'); expect(browserLocation.spy('pushState'))