[英]Angular2 Define child routes from sub-routing module
First of all, I've seen this post which seems to be close to my issue but I admit I got kind of lost : How to route to a Module as a child of a Module - Angular 2 RC 5 首先,我看过这篇帖子似乎与我的问题很接近,但我承认我有点迷失了: 如何作为Module的子级路由到Module-Angular 2 RC 5
I'll try to make it simple : 我将尝试使其简单:
app.component.html
file which has a <router-outlet>
. app.component.html
文件具有<router-outlet>
。 MasterModule
loads the MasterComponent
which has another <router-outlet>
. MasterModule
加载具有另一个<router-outlet>
的MasterComponent
。 From my MasterRoutingModule
, I can then define my child routes from my MasterComponent
. MasterRoutingModule
MasterComponent
定义子路由。 EquipmentSLModule
), which has his own routes, and my aim is to add child routes (to be loaded inside my second <router-outlet>
from MasterComponent
) from my EquipmentSLRouting
. EquipmentSLModule
),它具有自己的路由,我的目标是从我的EquipmentSLRouting
添加子路由(从MasterComponent
加载到我的第二个<router-outlet>
)。 Is there a way to do that ? 有没有办法做到这一点 ?
NB : I know there is no code yet, I'll edit and add some in a while. 注意:我知道目前还没有代码,我将在一段时间内进行编辑和添加。
Let's see if I understand what your asking. 让我们看看我是否理解您的要求。 Each Module can have it's own routing.
每个模块可以有自己的路由。 You can then reference that routing as children of a path like this:
然后,您可以将该路由作为路径的子级引用,如下所示:
In your AppRouting, load the routes from the : 在您的AppRouting中,从加载路线:
export const ROUTES: Routes = [
{
path: 'masterRoute',
loadChildren: './path/to/MasterRoutingModule.module#MasterRoutingModule' }
}
]
In your MasterRouting, load the EquipmentSLModule's routes as well to utilize the <router-outlet>
in the root component of the MasterModule: 在您的MasterRouting中,还要加载EquipmentSLModule的路由,以在MasterModule的根组件中利用
<router-outlet>
:
export const ROUTES: Routes = [
{ path: '', component: MasterComponent }, //root
{
path: 'otherRoute',
loadChildren: './path/to/EquipmentSLModule.module#EquipmentSLModule' }
}
]
This will load routes from the EquipmentSLModule
as routes in the MastRoutingModule. 这会将来自
EquipmentSLModule
路由作为MastRoutingModule中的路由加载。
In your EquipmentSLModule
you will import the routes for that module with RouterModule.forChild(routes)
, same for the MasterModule. 在您的
EquipmentSLModule
您将使用RouterModule.forChild(routes)
导入该模块的路由,与RouterModule.forChild(routes)
相同。 The AppModule will use RouterModule.forRoot(routes)
. AppModule将使用
RouterModule.forRoot(routes)
。
If you want to render your loaded module under a component <router-outlet></router-outlet>
hood you need to config as children's of particular component. 如果要在组件
<router-outlet></router-outlet>
引擎盖下渲染已加载的模块,则需要配置为特定组件的子组件。 I made a quick example for what you need, check out here is the link Plunker 我为您做了一个简单的示例,请查看此处的链接Plunker
imports: [BrowserModule,
RouterModule.forRoot([{
path: '',
pathMatch: 'full',
redirectTo: '/home'
},
{
path: 'home',
component: AppHome
children: [{
path: 'ModuleA',
loadChildren: 'src/ModuleA'
}]
},
])
]
Do something like this : 做这样的事情:
//...
const EquipmentSLRoutes: Routes = [
{ path: 'equipment-sl', component: EquipmentSLComponent },
{ path: 'equipment-sl/:id', component: EquipmentSLDetailComponent }
];
@NgModule({
imports: [
//...
RouterModule.forChild(EquipmentSLRoutes)
],
exports: [
//...
RouterModule
]
})
export class EquipmentSLModule { }
add this module to your MasterModule
imports array. 将此模块添加到您的
MasterModule
导入数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.