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

RouterStoreModule registers router listeners for every bootstrapped component #46

Open
chrisse27 opened this issue Mar 9, 2017 · 9 comments

Comments

@chrisse27
Copy link

chrisse27 commented Mar 9, 2017

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"
@chrisse27
Copy link
Author

@robwormald Any thoughts on this?

@brandonroberts
Copy link
Member

brandonroberts commented Mar 21, 2017 via email

@chrisse27
Copy link
Author

Thanks for the update @brandonroberts

@chrisse27
Copy link
Author

Let me know if I can help.

@chrisse27
Copy link
Author

@brandonroberts Is the code for this already in some branch that I could have a look at? Can I help with the release of the new version?

@chrissena
Copy link

I could be wrong but I think this repo has the future router-store.
Is that correct?

@dojchek
Copy link

dojchek commented Apr 9, 2017

@chrissena
I see this being mentioned for the second time now. I also use this library - tbh, I wouldn't like to go thru another router migration.. That would be the 3rd one for me :)

Can anyone please confirm this?

@brandonroberts
Copy link
Member

@dojchek there is a new version coming but it will be the same project. There will also be some breaking changes but the issue in question will be fixed in the new version. We just had ng-conf this past week but the new version will be released soon.

@dojchek
Copy link

dojchek commented Apr 10, 2017

@brandonroberts Thanks for the valuable info! This is awesome news 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants