fix(aio): strip leading slashes from path (and improve DRY-ness) (#16238)

Previously, the path returned by `LocationService.path()` preserved leading
slashes, which resulted in requests with consequtive slashes in the URL. Such
requests would fail (with a 404) on staging.

This commit fixes it, by removing leading slashes from the path. It also
refactors `LocationService` a bit, converting path to an observable,
`currentPath` (similar to `currentUrl`), and applies certain clean-ups (e.g.
stripping slashes, query, hash) in one place, which simplifies consumption.

Closes #16230
This commit is contained in:
George Kalpakas
2017-04-21 23:35:40 +03:00
committed by Miško Hevery
parent 062fc4afee
commit 9c1318d731
9 changed files with 228 additions and 97 deletions

View File

@ -3,12 +3,11 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
export class MockLocationService {
urlSubject = new BehaviorSubject<string>(this.initialUrl);
currentUrl = this.urlSubject.asObservable();
currentPath = this.currentUrl.map(url => url.match(/[^?#]*/)[0]);
search = jasmine.createSpy('search').and.returnValue({});
setSearch = jasmine.createSpy('setSearch');
go = jasmine.createSpy('Location.go').and
.callFake((url: string) => this.urlSubject.next(url));
path = jasmine.createSpy('Location.path').and
.callFake(() => this.urlSubject.getValue().split('?')[0]);
handleAnchorClick = jasmine.createSpy('Location.handleAnchorClick')
.and.returnValue(false); // prevent click from causing a browser navigation