Skip to content

Commit

Permalink
feat(router): restore whole object when navigating back to a page man…
Browse files Browse the repository at this point in the history
…aged by Angular router (#27198)

PR Close #27198
  • Loading branch information
jasonaden authored and IgorMinar committed Nov 30, 2018
1 parent 1b84b11 commit 2684249
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/router/src/router.ts
Expand Up @@ -181,7 +181,7 @@ export type NavigationTransition = {
reject: any,
promise: Promise<boolean>,
source: NavigationTrigger,
state: {navigationId: number} | null,
restoredState: {navigationId: number} | null,
currentSnapshot: RouterStateSnapshot,
targetSnapshot: RouterStateSnapshot | null,
currentRouterState: RouterState,
Expand Down Expand Up @@ -351,7 +351,7 @@ export class Router {
reject: null,
promise: Promise.resolve(true),
source: 'imperative',
state: null,
restoredState: null,
currentSnapshot: this.routerState.snapshot,
targetSnapshot: null,
currentRouterState: this.routerState,
Expand Down Expand Up @@ -393,7 +393,7 @@ export class Router {
switchMap(t => {
const transition = this.transitions.getValue();
eventsSubject.next(new NavigationStart(
t.id, this.serializeUrl(t.extractedUrl), t.source, t.state));
t.id, this.serializeUrl(t.extractedUrl), t.source, t.restoredState));
if (transition !== this.transitions.getValue()) {
return EMPTY;
}
Expand Down Expand Up @@ -431,9 +431,9 @@ export class Router {
* handle this "error condition" by navigating to the previously successful URL,
* but leaving the URL intact.*/
if (processPreviousUrl) {
const {id, extractedUrl, source, state, extras} = t;
const navStart =
new NavigationStart(id, this.serializeUrl(extractedUrl), source, state);
const {id, extractedUrl, source, restoredState, extras} = t;
const navStart = new NavigationStart(
id, this.serializeUrl(extractedUrl), source, restoredState);
eventsSubject.next(navStart);
const targetSnapshot =
createEmptyState(extractedUrl, this.rootComponentType).snapshot;
Expand Down Expand Up @@ -681,9 +681,9 @@ export class Router {
this.locationSubscription = <any>this.location.subscribe((change: any) => {
let rawUrlTree = this.parseUrl(change['url']);
const source: NavigationTrigger = change['type'] === 'popstate' ? 'popstate' : 'hashchange';
const state = change.state && change.state.navigationId ?
{navigationId: change.state.navigationId} :
null;
// Navigations coming from Angular router have a navigationId state property. When this
// exists, restore the state.
const state = change.state && change.state.navigationId ? change.state : null;
setTimeout(
() => { this.scheduleNavigation(rawUrlTree, source, state, {replaceUrl: true}); }, 0);
});
Expand Down Expand Up @@ -917,7 +917,7 @@ export class Router {
}

private scheduleNavigation(
rawUrl: UrlTree, source: NavigationTrigger, state: {navigationId: number}|null,
rawUrl: UrlTree, source: NavigationTrigger, restoredState: {navigationId: number}|null,
extras: NavigationExtras): Promise<boolean> {
const lastNavigation = this.getTransition();
// If the user triggers a navigation imperatively (e.g., by using navigateByUrl),
Expand Down Expand Up @@ -955,7 +955,7 @@ export class Router {
this.setTransition({
id,
source,
state,
restoredState,
currentUrlTree: this.currentUrlTree,
currentRawUrl: this.rawUrlTree, rawUrl, extras, resolve, reject, promise,
currentSnapshot: this.routerState.snapshot,
Expand Down

0 comments on commit 2684249

Please sign in to comment.