Resolve not invoked with lazy-loaded module using loadChildren as promise
See original GitHub issue🐞 bug report
Affected Package
RouterModule from @angular/router
Is this a regression?
I am running Angular 8 and I can reproduce in Angular 9
Description
When the feature module is lazy loaded, the resolver never gets called.
const routes: Routes = [
{
path: 'second',
loadChildren: () => import('/second/second.module')
.then(m => m.SecondModule),
resolve: {
data: SecondResolverService
}
},
I tried pre-loading and eager-loading the feature module, but the resolver is never invoked.
I’ve searched the issues but I cannot find anything related to this issue I’m seeing. I did find a stack overflow answer that said it should be working, but I can reproduce the issue fairly easily. (see “Minimal Reproduction” below)
This is the stackoverflow answer: https://stackoverflow.com/questions/53346976/resolver-on-lazy-loading-angular
Not sure if this is intended to be this way, if it is, it would be nice to state in the documentation. https://angular.io/api/router/Resolve https://angular.io/guide/lazy-loading-ngmodules#verify-lazy-loading https://angular.io/guide/router#lazy-loading-route-configuration https://angular.io/guide/router#preloading-background-loading-of-feature-areas From what I read, there is never an example where a resolver is used with lazy-loading module routes. But it’s also never explicitly stated that we should NOT use it this way, either.
🔬 Minimal Reproduction
Here is the stackblitz where the issue is reproducible: https://stackblitz.com/edit/angular-ivy-ubes1q?file=src%2Fapp%2Fapp.module.ts
(The child module is lazy loaded, the resolver never gets called, which is proven by the child guard in child module routes.)
🔥 Exception or Error
none
🌍 Your Environment
Angular Version: 8 and 9
Anything else relevant?
I did see this issue that maybe is related: #36193 but as the tags say it’s “confusing”
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Resolved by #38079, particularly this sentence in the docs for
Resolve
:The child route that you’re activating has a guard which returns false. Note that all guards are performed before the resolvers. The execution is not guard for parent config -> resolver for parent config -> guard for child config -> resolver for child config but rather guard for parent config -> guard for child config -> resolver for parent config -> resolver for child config