How can I activate a RouteGuard or Resolve on child routes within another module?
Example Scenario:
I have an application which has many separate modules, each defining their own routes. Consider these modules definining the following routes:
Module1 -> ['/a', '/b', '/c']
Module2 -> ['/d', '/e', '/f']
Now, I need to make sure that every route within the application has the following resolve:
resolve: { config: AppConfiguration}
We can use:
{ path: '', component: AppComponent, resolve: { config: AppConfiguration} }
However that achieves nothing -/
executes the resolver, but /a
does not.
The only way I've found to make sure routes /a
, /b
and /c
call the resolver, is if I make them children of the root as follows:
AppModule -> [ { path: '', component: 'MainComponent', resolver: {..}, children: [
...Module1Routes
...Module2Routes
] ]}
But by doing that this means the application is no longer structured in the way recommended by the Angular documentation, RouterModule.forChild()
is no longer used in other modules.
I'm sure this is a pretty common use case - is there a better way?