3

How to get Router config for lazy loaded module routes in Angular 2 Router?

When I log config on router object, only available routes from the module which has already been loaded are logged,

 export class AppComponent {
   constructor(private router: Router){
     console.log(router.config);
   } 
 }

router config

enter image description here

I understand since routes inside Lazy loaded modules are resolved at runtime, hence the config are not available. But it restricts us to get configuration data.

Is there a way in which we may get Route data from within the lazy loaded module without loading the module? Or define all routes in start and load the modules lazily?

Plunker

Thanks in advance!!


  • I mean you said it! Just declare routes in your code, export them from routing module, and import them where you need them. It's not as nice as accessing them as a property of router, but it works. - charlie_pl

1 답변


-1

use preloadingStrategy.

RouterModule.forRoot(
 appRoutes,
 {
  enableTracing: true, // <-- debugging purposes only
  preloadingStrategy: PreloadAllModules
 }
)


Related

Latest