1

My application requires dynamic loading of routes based on user, so the routing path is received as json from Database and parse to Routes object using JSON Parser. Dynamic route config working well if go with loadChildren parameter instead of component parameter, so in this case application routing to /dash, /contacts works successfully, but when route to \home application throws

Error : No component factory found for HomeComponent

I have tried configure the HomeComponent in entryComponents: [HomeComponent ] of NgModule in app.modules.ts file too, but issue not resolved

Route Json:

[{"path":"dash","loadChildren":"app/dash/dash.lazy.module#DashBoardModule"},
 {"path":"contacts","loadChildren":"app/contacts/contacts.lazy.module#ContactsModule"},
{"path":"home","component":"HomeComponent"}, 
{"path":"home","component":"HomeComponent",
"children": 
[{ "path": "child",   "loadChildren":"app/child/child.lazy.module#LazyModule", 
"outlet": "mainoutlet" }]
}]

Json to Routes

export class AppComponent implements OnInit {
......
appRoutes: Routes;
 routejson: string

public loadRouteFromString() {
    this.routejson = httpcalltogetRouteJsonString();
    this.appRoutes = JSON.parse(this.routejson);
    this.router.resetConfig(this.appRoutes);
    this.router.navigate(['/dash']);   
  }
...
}
Jeevanantham
  • 984
  • 3
  • 19
  • 48

0 Answers0