我正在将正在开发的应用程序升级到最新的Angular 2候选版本.作为这项工作的一部分,我正在try 使用NgModule规范,并将应用程序的所有部分迁移到模块中.在大多数情况下,除了路由问题外,这一切都进行得很顺利.
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
我的应用程序由多个模块组成,几个模块作为父模块的子模块粘在一起.例如,我有一个管理模块,它包括一个通知模块、一个用户模块和一个电话语音模块(例如).这些模块的路径应该是...
/admin/notifications/my-notifications
/admin/users/new-user
/admin/telephony/whatever
在路由的早期版本中,使用" children "很容易做到这一点
export const AdminRoutes: RouterConfig = [
{
path: "Admin",
component: AdminComponent,
Children: [
...UserRoutes,
...TelephonyRoutes,
...NotificationRoutes
]
}
]
在另一个文件中,作为子模块的一部分,我还将定义单独的模块路由.
export const UserRoutes: RouterConfig = [
{
path: "users",
component: userComponent,
children: [
{path: "new-user", component: newUserComponent}
]
}
]
这一切都运作得很好.在升级到模块的过程中,我将所有内容都移到了各自的路由文件中,所以现在这两个文件看起来更像这样
const AdminRoutes: Routes = [
{path: "admin", component: AdminComponent}
]
export const adminRouting = RouterModule.forChild(AdminRoutes)
和
const UserRoutes: Routes = [
path: "users",
component: userComponent,
children: [
{path: "new-user", component: newUserComponent}
]
]
export const userRouting = RouterModule.forChild(UserRoutes)
With all of that in place, I have a UsersModule which imports the userRouting, 和 then an AdminModule that imports the adminRoutes 和 the UsersModule. My thought was that since UsersModule is a child of AdminModule, the routing would work the way it used to. Unfortunately, it doesn't so I end up with a users route that is just
/users/new-user
而不是
/admin/users/new-user
Further, because of this, the new-user component isn't loaded into the router outlet of my admin component which throws off the styling 和 navigation of my application.
I can't for the life of me come up with how to reference the routes of my UserModule as children of my AdminModule. I've tried doing this the old way 和 get errors about the routes being in two Modules. Obviously since this is newly released, the documentation around some of these cases is a bit limited.
任何人所能提供的任何帮助都将不胜感激!