我在单个应用程序中创建了多个角度项目。我在根项目中使用了路由并尝试与子项目进行通信,但发生的情况是 url 被更改但页面未呈现。
根页面路由:
export const routes: Routes = [
{
path: '',
redirectTo: 'dashboard',
pathMatch: 'full',
},
{
path: '',
component: DefaultLayoutComponent,
data: {
title: 'Home'
},
children: [
{
path: 'dashboard',
loadChildren: './views/dashboard/dashboard.module#DashboardModule'
},
{
path: 'flights',
loadChildren: '../../projects/flights/src/app/flight.module#FlightsSharedModule'
},
{
path: 'passengers',
loadChildren: '../../projects/passengers/src/app/app.module#PassengersSharedModule'
}
]
},
{ path: '**', component: DefaultLayoutComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(routes),
FlightsSharedModule.forRoot(),
PassengersSharedModule.forRoot()
],
exports: [ RouterModule ]
})
航班申请途径:
const routes: Routes = [{
path: '',
data: {
title: 'Flights',
},
children: [
{
path: '',
component: ListComponent,
data: {
title: 'List',
},
},
],
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
旅客申请途径
const routes: Routes = [{
path: '',
data: {
title: 'Passengers',
},
children: [
{
path: '',
component: ListComponent,
data: {
title: 'List',
},
},
],
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
在根应用程序路由中,如果我从根目录中删除模块,则页面显示如下级联效果
但是,如果将这些项目作为模块导入,则页面不会呈现特定组件,而是显示默认主页,而是显示第一个应用程序,如下所示