X Tutup
Skip to content

Commit e372cc7

Browse files
matskobtford
authored andcommitted
fix(router): do not prepend the root URL with a starting slash
1 parent 6834c49 commit e372cc7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

modules/angular2/src/router/location.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class Location {
2121
normalize(url: string): string { return this._stripBaseHref(stripIndexHtml(url)); }
2222

2323
normalizeAbsolutely(url: string): string {
24-
if (url[0] != '/') {
24+
if (url.length > 0 && url[0] != '/') {
2525
url = '/' + url;
2626
}
2727
return this._addBaseHref(url);

modules/angular2/test/router/location_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export function main() {
3535
.toHaveBeenCalledWith(null, '', '/my/app/user/btford');
3636
});
3737

38+
it('should not prepend urls with starting slash when an empty URL is provided',
39+
() => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.baseHref); });
40+
3841
it('should not append urls with leading slash on navigate', () => {
3942
location.go('/my/app/user/btford');
4043
expect(browserLocation.spy('pushState'))

0 commit comments

Comments
 (0)
X Tutup