We are using ngrx in a setup where an app consists of multiple components:
@NgModule({
declarations: [
AppComponent1,
AppComponent2,
],
imports: [
BrowserModule,
RouterModule.forRoot(routes),
RouterStoreModule.connectRouter(),
StoreModule.provideStore(reducer),
],
providers: [...],
bootstrap: [AppComponent1, AppComponent2]
})
export class DemoModule {
}
RouterStoreModule.connectRouter() registers an APP_BOOTSTRAP_LISTENER that is supposed to register a bunch of router/store listeners during the bootstrap process. However, it registers these listeners every single time a component is bootstrapped.
Looking at how the router handles the bootstrap process one can see that it contains a little if to ensure that only initializes things once:
export function initialRouterNavigation(
router: Router, ref: ApplicationRef, preloader: RouterPreloader, opts: ExtraOptions) {
return (bootstrappedComponentRef: ComponentRef<any>) => {
if (bootstrappedComponentRef !== ref.components[0]) {
return;
}
...
The router store should just do the same.
Current NPM config:
"@angular/common": "^2.4.5",
"@angular/compiler": "^2.4.5",
"@angular/core": "^2.4.5",
"@angular/forms": "^2.4.5",
"@angular/http": "^2.4.5",
"@angular/platform-browser": "^2.4.5",
"@angular/platform-browser-dynamic": "^2.4.5",
"@angular/router": "^3.3.1",
"@ngrx/core": "^1.1.0",
"@ngrx/effects": "^2.0.0",
"@ngrx/router-store": "^1.2.5",
"@ngrx/store": "^2.2.1"