Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular reuse same lazy load module for multiple root paths

I've splitted my app into two modules: one with main basic functionality and other with less-used features like account settings, faq pages and more.

What I'm trying to accomplish is to lazy load the second module for some root route paths, like /account or /settings without having to create many different modules. As far as I know Angular lazy load only works with one root route, and the routes configured in the lazy loaded module are set as children of that route.

 {
        path: 'account',
        loadChildren: './modules/settings/settings.module#SettingsModule',
 },
 {
        path: 'settings',
        loadChildren: './modules/settings/settings.module#SettingsModule',
 },
like image 900
Javier Marín Avatar asked Jan 20 '26 03:01

Javier Marín


1 Answers

The Angular team is working on standalone components, that could potentially make loading some rarely used parts less painful:

https://blog.angular.io/an-update-on-standalone-components-ea53b4d55214

One easy (although not 100% optimal) way that is good enough for a lot of requirements probably is using a single shared module - that way your extra overhead is "just" to create another feature module

like image 133
Mario B Avatar answered Jan 21 '26 21:01

Mario B