我正尝试使用如下所示的延迟加载的模块路由,但找不到URL localhost:4200/authorization/opcodes
的匹配项。它可以加载主页。
src \ app \ app-routing.module.ts
const routes: Routes = [
{
path: '',
loadChildren: './modules/main-page/main-page.module#MainPageModule'
},
{
path: 'feature',
loadChildren: './modules/feature/feature.module#FeatureModule'
}
];
src \ app \ modules \ main \ page \ main-page-routing.module.ts
const routes: Routes = [
{
path: '',
component: MainPageComponent,
canActivate: [AuthGuard],
children:[
{
path: 'authorization',
loadChildren: './authorization/authorization.module#AuthorizationModule'
}
]
}
];
src \ app \ modules \ main \ page \ authorization \ authorization-routing.module.ts
const routes: Routes = [
{
path: 'opcodes',
component: OpCodeComponent
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
MainPageComponent是主要布局,其中包括将托管OpCodesComponent的路由器出口。
因此,路由器流应为:AppRouterModule-> MainPageRouterModule-> AuthorizationRouterModule。
答案 0 :(得分:0)
我发现了问题。显然,我忘记了将AuthorizationRoutingModule导入到AuthorizationModule中。该框架没有给出任何暗示的警告。如果Angular明确警告这一点,将会很有帮助。