feat(router): add navigationSource and restoredState to NavigationStart event (#21728)

Currently, NavigationStart there is no way to know if an navigation was triggered imperatively or via the location change. These two use cases should be handled differently for a variety of use cases (e.g., scroll position restoration). This PR adds a navigation source field and restored navigation id (passed to navigations triggered by a URL change).

PR Close #21728
This commit is contained in:
vsavkin
2018-01-24 12:19:59 -05:00
committed by Jason Aden
parent 5bd93b1f0f
commit c40ae7f7cf
10 changed files with 183 additions and 40 deletions

View File

@ -182,12 +182,12 @@ export declare class Location {
constructor(platformStrategy: LocationStrategy);
back(): void;
forward(): void;
go(path: string, query?: string): void;
go(path: string, query?: string, state?: any): void;
isCurrentPathEqualTo(path: string, query?: string): boolean;
normalize(url: string): string;
path(includeHash?: boolean): string;
prepareExternalUrl(url: string): string;
replaceState(path: string, query?: string): void;
replaceState(path: string, query?: string, state?: any): void;
subscribe(onNext: (value: PopStateEvent) => void, onThrow?: ((exception: any) => void) | null, onReturn?: (() => void) | null): ISubscription;
static joinWithSlash(start: string, end: string): string;
static normalizeQueryParams(params: string): string;
@ -199,6 +199,7 @@ export declare const LOCATION_INITIALIZED: InjectionToken<Promise<any>>;
/** @experimental */
export interface LocationChangeEvent {
state: any;
type: string;
}
@ -415,6 +416,7 @@ export declare enum Plural {
/** @experimental */
export interface PopStateEvent {
pop?: boolean;
state?: any;
type?: string;
url?: string;
}

View File

@ -21,12 +21,12 @@ export declare class SpyLocation implements Location {
urlChanges: string[];
back(): void;
forward(): void;
go(path: string, query?: string): void;
go(path: string, query?: string, state?: any): void;
isCurrentPathEqualTo(path: string, query?: string): boolean;
normalize(url: string): string;
path(): string;
prepareExternalUrl(url: string): string;
replaceState(path: string, query?: string): void;
replaceState(path: string, query?: string, state?: any): void;
setBaseHref(url: string): void;
setInitialPath(url: string): void;
simulateHashChange(pathname: string): void;