X Tutup
Skip to content

Commit cdc7b03

Browse files
matskobtford
authored andcommitted
fix(router): avoid two slash values between the baseHref and the path
1 parent e372cc7 commit cdc7b03

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

modules/angular2/src/router/location.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ function stripIndexHtml(url: string): string {
6262
if (url.length > 10 && StringWrapper.substring(url, url.length - 11) == '/index.html') {
6363
return StringWrapper.substring(url, 0, url.length - 11);
6464
}
65+
if (url.length > 1 && url[url.length - 1] == '/') {
66+
url = StringWrapper.substring(url, 0, url.length - 1);
67+
}
6568
return url;
6669
}

modules/angular2/test/router/location_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export function main() {
3838
it('should not prepend urls with starting slash when an empty URL is provided',
3939
() => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.baseHref); });
4040

41+
it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => {
42+
browserLocation = new DummyBrowserLocation();
43+
browserLocation.spy('pushState');
44+
browserLocation.baseHref = '/my/slashed/app/';
45+
location = new Location(browserLocation);
46+
expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page');
47+
});
48+
4149
it('should not append urls with leading slash on navigate', () => {
4250
location.go('/my/app/user/btford');
4351
expect(browserLocation.spy('pushState'))

0 commit comments

Comments
 (0)
X Tutup