1

我的应用程序需要基于用户动态加载路由,因此路由路径作为 json 从数据库接收并使用 JSON Parser 解析为 Routes 对象。loadChildren如果使用参数而不是参数,则动态路由配置运行良好component,因此在这种情况下,应用程序路由到/dash/contacts成功工作,但是当路由到\home应用程序抛出

错误 :No component factory found for HomeComponent

我也尝试过配置inHomeComponent文件,但问题没有解决entryComponents: [HomeComponent ]NgModuleapp.modules.ts

路线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 到路由

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']);   
  }
...
}
4

0 回答 0