We have some modules that come with their own navigation bars. These nav bars are actual components and they activated in the global HeaderComponent
of the app as soon as the corresponding route is activated.
To pass the navigation component we use the data
property of the route in app-routing.module.ts
:
import { TestNavigationComponent } from './modules/test/components/test-navigation/test-navigation.component';
{
path: 'test',
loadChildren: () => import('./modules/test/test.module').then(m => m.TestModule),
data: {
nav: TestNavigationComponent
},
},
While this works fine, I wonder:
Does this circumvent lazy loading of the module? Is the module loaded anyway, because the navigation component is imported in the gobal app-routing.module.ts
already?
If yes, how could I bundle the navigation component along with the module and pass it to the application's header?
The naviagtion is rendered in the header component like this currently:
private updateNavigation(snapshot: ActivatedRouteSnapshot): void {
const nav: Type<Component> = (snapshot.data as {nav: Type<Component>}).nav;
if (nav instanceof Type) {
if (nav === this.navigationType) {
return;
}
this.clearNavigation();
this.navigationType = nav;
const factory: ComponentFactory<Component> = this.componentFactoryResolver.resolveComponentFactory(nav);
this.navigationComponentRef = this.navigationRef.createComponent(factory);
return;
}
for (let childSnapshot of snapshot.children) {
this.updateNavigation(childSnapshot);
}
}