我正在尝试在主路由器插座内使用辅助路由器插座。
应用程序路由
export const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{
path: 'page',
loadChildren: () => new Promise(function (resolve) {
(require as any).ensure([], function (require: any) {
resolve(require('../pages/page.module').default);
});
})
}
];
应用程序组件
@Component({
template: `<h1>My App!</h1>
<a [routerLink]="['/page']">Page</a>
<router-outlet></router-outlet>`
})
页面模块
@NgModule({
imports: [
CommonModule,
RouterModule.forChild([
{
path: '',
component: PageComponent
},
{
path: 'auxpath',
component: AuxComponent,
outlet: 'auxoutlet'
}
])
],
declarations: [PageComponent],
exports: [PageComponent]
})
export default class PageModule {}
页面组件
@Component({
template: `Page <router-outlet name="auxoutlet"></router-outlet>`
})
辅助组件
@Component({
template: `Aux`
})
错误 /page/(auxoutlet:auxpath)将看到页面组件,但出现此错误:
EXCEPTION: Uncaught (in promise): Error: Cannot find the outlet auxoutlet to load 'AuxComponent'