From e372cc779dcd77ae7a77de7a8dc96aac38ff3910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 12 Jun 2015 11:29:31 -0700 Subject: [PATCH] fix(router): do not prepend the root URL with a starting slash --- modules/angular2/src/router/location.ts | 2 +- modules/angular2/test/router/location_spec.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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'))