I want to have a route in my app where I could list all existing routes in the application. I'm in Angular 9 with Ivy and use the dynamic import for lazy loading.
The application have some modules that are lazy loaded. This route will be declared in the root module. But at this time the router.config
only contains the "root" routes and the lazy ones have a loadChildren()` method with the dynamic import of the module.
I tried things like this one : Lazy load module in angular 8 but couldn't make it to work for the routes. The router instance don't seems to be updated.
Looking at the source code of the router, I've succeeded to load the lazy module and get the children routes using the load method of the configLoader
(<any> this.router).configLoader.load(this.injector, route).subscribe({
next: (moduleConf) => {
children.push(...moduleConf.routes.map((childRoute) => childRoute.path));
}
})
It works well, but I use the configLoader
property of the Router
and it's a private property. So it is not a very good idea for the future :)
I've made a stackblitz where you can see/test the code.
The component have also a loadConfOld()
method that is an unsuccessful try with the moduleFactory
.
How can I do what I want in a proper and durable way ? Thank you in advance for your help.