Skip to content

Commit

Permalink
fix(router-store): don't navigate on NavigationStart router event (#1379
Browse files Browse the repository at this point in the history
)
  • Loading branch information
timdeschryver authored and brandonroberts committed Oct 26, 2018
1 parent 7463727 commit 6ea4148
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/router-store/src/router_store_module.ts
Expand Up @@ -11,6 +11,8 @@ import {
Router,
RouterStateSnapshot,
RoutesRecognized,
Event,
NavigationStart,
} from '@angular/router';
import { select, Store } from '@ngrx/store';
import { of } from 'rxjs';
Expand Down Expand Up @@ -223,6 +225,7 @@ export class StoreRouterConnectingModule {
};
}

private lastEvent: Event | null = null;
private routerState: SerializedRouterStateSnapshot;
private storeState: any;
private lastRoutesRecognized: RoutesRecognized;
Expand Down Expand Up @@ -266,6 +269,7 @@ export class StoreRouterConnectingModule {
}

private shouldDispatchRouterNavigation(): boolean {
if (this.lastEvent instanceof NavigationStart) return false;
if (!this.storeState[this.stateKey]) return true;
return !this.navigationTriggeredByDispatch;
}
Expand All @@ -287,6 +291,8 @@ export class StoreRouterConnectingModule {

private setUpStateRollbackEvents(): void {
this.router.events.subscribe(e => {
this.lastEvent = e;

if (e instanceof RoutesRecognized) {
this.lastRoutesRecognized = e;
} else if (e instanceof NavigationCancel) {
Expand Down

0 comments on commit 6ea4148

Please sign in to comment.