简体   繁体   中英

Getting Router config for lazy loaded module in Angular 2 Router

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

在此处输入图片说明

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!!

use preloadingStrategy.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM