We can lazy load a local module like this module
{
path: 'somePpath',
loadChildren: 'app/path/some.module#SomeModule'
},
How do we lazy load a module that comes from an external library resides in node_modules?
To load an external module in the router module you might need to use a Wrapper module. Create a wrapper module in the same local project in which you are having your routing module. Import your external module in this wrapper module with traditional import syntax.
import { SomeModule } from '@externalLib';
Include this module in the imports of NgModule
's import array.
@NgModule({
imports: [SomeModule]
})
export class SomeWrapperModule {
}
Then use this wrapper module in the router module as we usually use a module.
// for Angular 7 and below
{
path: 'some-path',
loadChildren: '../somewrapper.module#SomeWrapperModule'
}
// for Angular 8+
{
path: 'some-path',
loadChildren: () => import('../somewrapper.module').then(mod => mod.SomeWrapperModule)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With