7

Angular 2.4.8... My app has a primary module with its own routing module. It lazy loads a secondary module with its own routing module. The primary module references the secondary routing module so Angular keeps track of the routing arrays in proper order and everything works groovy.

The secondary module declares a custom provider that implements RouterReuseStrategy so it can reuse one of its child components. This worked great while the primary module directly referenced the secondary module, pre-loading everything up front.

But then I changed the primary route to lazy load the secondary module and the custom RouterReuseStrategy provider stopped working altogether, in fact its constructor isn't even invoked.

The primary module declares the provider like this: providers: [{ provide: RouteReuseStrategy, useClass: CustomReuseStrategy }]

The primary routing module lazy loads the secondary module like this: loadChildren: '../foo/foo.module#FooModule'.

More simply: Can a module both have its own RouterReuseStrategy and be lazy loaded?

Any help would be greatly appreciated!

stemarcoh
  • 111
  • 3
  • Hi. did you manage to find the answer? I'm having similiar problem. – Jarosław Rewers Apr 19 '17 at 08:20
  • No I haven't. I'm surprised it's not a more common scenario. If you're so worried about the load time and want to lazy load it then I would presume you also want to keep it in memory with a custom reuse strategy. – stemarcoh Apr 20 '17 at 10:23
  • 1
    at this point I'm implementing custom reuse strategy at root module level but it's serious problem, there are only unanswered questions regarding this on stackoverflow :) – Jarosław Rewers Apr 20 '17 at 11:04
  • See the answer in this [link,](https://stackoverflow.com/questions/42383546/angular2-doesnt-work-custom-reuse-strategy-with-lazy-module-loading) worked for me perfectly. – Nikita Marinosyan Nov 27 '17 at 22:24
  • Possible duplicate of [Angular2 doesn't work Custom Reuse Strategy with Lazy module loading](https://stackoverflow.com/questions/42383546/angular2-doesnt-work-custom-reuse-strategy-with-lazy-module-loading) – Stepan Suvorov May 01 '19 at 09:31

1 Answers1

0

Answer is provided here Angular2 doesn't work Custom Reuse Strategy with Lazy module loading

in short:

RouteReuseStrategy does work with LazyLoaded components.

Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176