【问题标题】:Global routing between angular modules角度模块之间的全局路由
【发布时间】:2017-05-02 23:14:27
【问题描述】:

我在我的项目中使用 Angular2,我有几个模块。

我有一个名为BaseModule 的基本模块 并拥有例如两个(或更多)额外模块 - FirstModuleSecondModule

每个模块都有自己的路由。 BaseModule 有系统的基本路线, FirstModuleSecondModule 有自己分开的路线。

但是

我想创建类似的路线

/user/10/profile

用户的ProfileComponent 包含在FirstModule

其他例子

/user/10/stories

用户的StoriesComponent 包含在FirstModule

/user/10/news

用户的NewsComponent 包含在SecondModule 中!!!!

但是 Angular 路由器只允许这样的路由:

/firstmodule/......

/secondmodule/......

因此,它们应该按模块分组。

我想用模块来做这件事,因为我想让我的应用程序的异步(惰性)加载部分。

据我所知,当我们异步(延迟)加载组件时,Angular 不允许变体。

任何人都知道如何创建我想要的东西?

【问题讨论】:

    标签: javascript angular


    【解决方案1】:

    对于根模块中的路由,将根定义为RouterModule.forRoot(['']),对于其他模块中的路由,使用RouterModule.forChild([''])。由于您的子模块将位于父模块的imports 中,因此可以正确路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 2018-06-23
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多