[英]Angular 6/7/8 Nested Child Routes using 'loadChildren()', not displaying
[英]Angular - multiple routes for a component with loadChildren?
我正在嘗試為子組件設置多個角度路由,並且必須使用延遲加載 (loadChildren)。
正如我們所見, /page1/ from1和/page2/from2應該顯示 show MyComponent ,但/page1/from2不能路由到MyComponent 。
這是我嘗試過的:
應用路由:
const routes: Routes = [
{ path: 'page1', loadChildren: () => import(`./MyComponentModule.module`).then(x => x.MyComponentModule) },
{ path: 'page2', loadChildren: () => import(`./MyComponentModule.module`).then(x => x.MyComponentModule) }
];
組件模塊路由:
const routes: Routes = [
{ path: 'from1', component: MyComponentModule },
{ path: 'from2', component: MyComponentModule }
];
此解決方案的問題
這匹配 /page1/from2 以及 /page2/from1,這不是我需要的。 有沒有一種優雅的方法來做到這一點?
您可以使用路由器參數
const routes: Routes = [
{ path: 'page/:id', loadChildren: () => import(`./MyComponentModule.module`).then(x => x.MyComponentModule) },
];
.
const routes: Routes = [
{ path: 'from/:id', component: MyComponentModule },
];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.