Angular 2 RouterReuseStrategy Provider and Lazy Loaded Module

Angular 2.4.8 ... My application has a primary module with its own routing module. It lazily loads an additional module with its own routing module. The primary module refers to the secondary routing module, so Angular tracks the routing arrays in the correct order, and everything works groovy.

The secondary module announces a custom provider that implements RouterReuseStrategy so that it can reuse one of its child components. This worked fine, while the primary module directly referenced the secondary module, preloading everything along the edge.

But then I changed the main route to lazy loading the secondary module, and the custom provider RouterReuseStrategy stopped working at all, in fact its constructor is not even called.

The main module declares the provider as follows: providers: [{provide: RouteReuseStrategy, useClass: CustomReuseStrategy}]

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

The easiest way . Can a module have its own RouterReuseStrategy and be lazy loaded?

Any help would be greatly appreciated!

+6
source share
1 answer

The answer is presented here. Angular2 does not work. User reuse strategy with loading lazy modules.

in short:

RouteReuseStrategy works with LazyLoaded components.

0
source

Source: https://habr.com/ru/post/1015453/


All Articles