Home:ALL Converter>Dynamic routing in Angular from Json

Dynamic routing in Angular from Json

Ask Time:2020-09-18T00:13:47         Author:14m12007

Json Formatter

So I have an important Question. Is it possible to achieve async routing in Angular 10 ? I have read about the AsyncRoute in Angular2, but this one doesn't exist anymore in Angular 10.

My Code looks like this :

 getRoutes() {
   return this.http.get(this.APIROOT + 'routes');
 }

pageService.getRoutes().subscribe( (pageRoutes:RouteInterface[]) => {
     const componentMap = {
       'PageComponent': PageComponent,
       'BlogComponent':BlogComponent
     };
     for(let route of pageRoutes){
       this.routes.push({ 'path' : route.route, 'component' : componentMap[route.component]})
     }
   }) 

This will result in an valid and correct :Route Array. My Problem is that this Data isnt synchronous. Its asynchronous. So i cant just push the data to the route:Routes Array in the app-routing.module.ts via the constructor. Is there any other way to achieve this ? Does anyone has experience with that ?

Author:14m12007,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/63942133/dynamic-routing-in-angular-from-json
yy