當使用loadChildren()調用導入子路由時,我遇到了覆蓋根路由的問題。Angular2子模塊的forChild()路由覆蓋根路由
應用路線聲明:
const routes: Routes = [
{ path: '', redirectTo: 'own', pathMatch: 'full' },
{ path: 'own', component: OwnComponent },
{ path: 'nested', loadChildren:() => NestedModule},
];
export const routing = RouterModule.forRoot(routes);
嵌套子模塊的路線:
const routes: Routes = [
{ path: 'page1', component: NestedPage1Component },
{ path: 'page2', component: NestedPage2Component },
{ path: '', redirectTo: 'page1', pathMatch: 'full' },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class Module1RoutingModule {}
我可以/自己,/嵌套/第1頁,/嵌套/第2頁,但是當我試圖讓根/ - 我正在重定向到/ page1。爲什麼會發生這種情況,因爲它是在RouterModule.forChild的子模塊中聲明的,它如何不重定向到/ own?
我創建簡單的普拉克攝製 - https://plnkr.co/edit/8FE7C5JyiqjRZZvCCxXB?p=preview
是否有人經歷了這種行爲?
對於其他人來說,[這個github問題](https://github.com/angular/angular/issues/10958)討論了這種路由行爲。 – makman99