fix(aio): AppComponent should scroll only once when location changes

This commit is contained in:
Ward Bell
2017-04-24 14:34:31 -07:00
committed by Pete Bacon Darwin
parent 710b4a3503
commit ac5e6baced
4 changed files with 60 additions and 16 deletions

View File

@ -2,7 +2,8 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
export class MockLocationService {
urlSubject = new BehaviorSubject<string>(this.initialUrl);
currentUrl = this.urlSubject.asObservable();
currentUrl = this.urlSubject.asObservable().map(url => this.stripSlashes(url));
// strip off query and hash
currentPath = this.currentUrl.map(url => url.match(/[^?#]*/)[0]);
search = jasmine.createSpy('search').and.returnValue({});
setSearch = jasmine.createSpy('setSearch');
@ -12,5 +13,9 @@ export class MockLocationService {
.and.returnValue(false); // prevent click from causing a browser navigation
constructor(private initialUrl) {}
private stripSlashes(url: string) {
return url.replace(/^\/+/, '').replace(/\/+(\?|#|$)/, '$1');
}
}