问题:我有一个懒人模块想要在我的app.component.html中使用弹出路由器。
我的应用组件模板中有以下内容:
的src /应用程序/ app.component.html
<!-- Primary Router -->
<router-outlet id="main-router"></router-outlet>
<!-- Popup Router -->
<router-outlet name="app-popup"></router-outlet> <!-- <--------- -->
/src/app/app-routing.module.ts
const appRoutes: Routes = [
{ path: 'lazy', loadChildren: 'app/lazy/lazy.module#LazyModule' }, // <--------
];
@NgModule({
imports: [
CommonModule,
RouterModule.forRoot(appRoutes),
],
exports: [
RouterModule
],
})
export class AppRoutingModule { }
/src/app/app.module.ts
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
/src/app/lazy/lazy.module.ts
const lazyRoutes: Routes = [
{ path: 'lazy-popup', outlet: 'app-popup', component: LazyPopupComponent },
{ path: '', component: LazyComponent }
];
@NgModule({
imports: [
RouterModule.forChild(lazyRoutes)
],
exports: [
RouterModule
]
})
export class LazyRoutingModule {}
/src/app/lazy/lazy.module.ts
@NgModule({
imports: [
CommonModule,
AppSharedModule,
LazyRoutingModule
],
declarations: [
LazyComponent,
LazyPopupComponent
],
exports: [
LazyPopupComponent,
LazyRoutingModule,
]
})
export class LazyModule {}
当我收到此错误时,我似乎无法正常工作:
core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: Cannot match
any routes. URL Segment: 'lazy-popup'.
请注意,如果我在下面的AppModule中导入LazyModule,这可以很好地工作:
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule,
LazyModule // <-- This routes works now.. But.. this should be lazy.. : (
],
bootstrap: [AppComponent]
})
export class AppModule {}
虽然这违背了它是一个懒惰加载模块的目的。那么我怎样才能让延迟加载的模块使用名为&#39; app-popup&#39;的二级路由器插座。应用程序组件html模板中存在哪些?
我导航到这样的路线:
/src/app/lazy/lazy.component.html
<button [routerLink]=" [ '', { outlets: { 'app-popup': ['lazy-popup'] } }] "></button>