简体   繁体   中英

Angular 8 - How to dynamiclaly add children routes

I have a parent module, client-migration.module.ts that is being lazily loaded in app-routing.module.ts . In client-migration-routing.module.ts , I need to somehow load routes that are coming from a service. How can I achieve that?

According to your question I think what you need is Multiple Router Outlets so that you can dynamically load different components in different sections of your page.
Here one is primary outlet and second is named outlet

<router-outlet></router-outlet>  
<router-outlet  name="sidebar"></router-outlet> 

In your routing.module.ts you can add route like this.

{
   path: "",
   component: SidebarComponent,
   outlet: "sidebar"
}

You can call the service no problem in that.

That's it you are good to go, here is the reference Link

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