这里我有一个路由路径后跟两个路由参数,路由看起来像 section/sectionId/dashboardId
:
const appRoutes: Routes = [
{
path: 'section/:sectionId',
component: SectionComponent,
children: [
{
path: ':dashboardId',
component: DashboardComponent
},
]
},
];
我需要的是添加一个无组件的第三个参数 . 我需要将它用作ID作为参数,我可以传递给我的一个组件 . 所以我尝试了这个:
const appRoutes: Routes = [
{
path: 'section/:sectionId',
component: SectionComponent,
children: [
{
path: ':dashboardId',
component: DashboardComponent,
children: [
{
path: ':dashboardParam',
},
]
},
]
},
];
我得到了拒绝承诺,说“必须提供以下其中一项:component,redirectTo,children或loadChildren” .
所以我将 redirectTo: ':dashboardId'
添加到 :dashboardParam
子路由,我得到"Cannot redirect to ':dashboardId'. Cannot find ':dashboardId'."
如何在不收到错误的情况下添加第三个参数?
1 回答
实际上,如果没有相应的组件去或重定向,你就无法编写路由 . 你可以写这样的
并在组件中检查
dashboardParam
参数是否已通过组件传递给组件