1

Does it matter where the resolver exists in Angular in these two examples? Both of these two snippets of code achieve the same result:

Placing the resolver at the module-level within AppModule:

const routes: Routes = [
  {
    path: 'user',
    resolve: {
      user: UserResolver
    },
    loadChildren: () => import('./user/user.module').then(m => m.UserModule)
  },
];

vs. placing it directly on the component (with children routes) for the routing defined inside the UserModule:

const routes: Routes = [
  {
    path: '',
    component: UserComponent,
    resolve: {
      user: UserResolver
    },
    children: [
      {
        path: 'details',
        component: DetailsComponent,
      },
      {
        path: 'change-password',
        component: ChangePasswordComponent,
      },
    ],
  },
];

What is the difference between resolving the data at the module level, vs. resolving it at the component level, with children routes?

keldar
  • 6,152
  • 10
  • 52
  • 82

1 Answers1

0

According to my understanding of it :

On the module level, the resolve will only run when the module is accessed/loaded, and As for the component level whichever component you put your resolve on will work.