Skip to content
This repository was archived by the owner on Jul 27, 2018. It is now read-only.
This repository was archived by the owner on Jul 27, 2018. It is now read-only.

RouterStoreModule registers router listeners for every bootstrapped component #46

@chrisse27

Description

@chrisse27

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions