相关疑难解决方法(0)

Angular 2中模块之间的路由

我正在编写一个应用程序,其中所有功能都有自己的模块(功能可以是页面,也可以是页面的一部分).这是因为我们希望所有功能都拥有自己的域逻辑,服务,指令和组件,即在仪表板模块中我们得到了一个ChartComponent小部件,我不想将其暴露给其他视图,如登录或配置文件.

问题是当在Angular 2中使用路由时,您总是路由到特定组件,而不是模块.

在我们的例子中,为路径设置路径:'/ dashboard'组件:DashboardComponent我们需要在app.module.ts中声明DashboardComponent,这没关系,但是因为我们仍然在模块app.module中我们的CharComponent是因为它是在dashboard.module.ts而不是app.module.ts中声明的,所以我们的DashboardComponent中没有公开并且不会渲染.

如果我们在app.module.ts中声明ChartComponent它应该正常工作但我们失去了应用程序的架构.

应用程序的文件结构如下:

?? src/
   ?? app/
      ?? app.module.ts
      ?? app.component.ts
      ?? app.routing.ts
      ?? profile/
      |  ?? profile.module.ts
      |  ?? profile.component.ts
      ?? login/
      |  ?? login.module.ts
      |  ?? login.component.ts
      ?? dashboard/
         ?? dashboard.module.ts
         ?? dashboard.component.ts
            ?? chart/
               ?? chart.component.ts
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

23
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1

angular2-routing ×1