Angular 2+个连续的路由参数;最后一个无组件
Angular 2+ consecutive route params; the last one componentless
这里我有一个路由路径,后跟两个路由参数,路由看起来像 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',
},
]
},
]
},
];
我收到了拒绝的承诺,上面写着 "One of the following must be provided: component, redirectTo, children or loadChildren"。
所以我将 redirectTo: ':dashboardId'
添加到 :dashboardParam
子路由,然后我得到 "Cannot redirect to ':dashboardId'. Cannot find ':dashboardId'."
如何在不出现错误的情况下添加这第三个参数?
实际上你不能写一个没有相应组件去或重定向的路由。你可以这样写
const appRoutes: Routes = [
{
path: 'section/:sectionId',
component: SectionComponent,
children: [
{
path: ':dashboardId/:dashboardParam',
component: DashboardComponent
},
]
},
];
并在组件中检查 dashboardParam
参数是否通过
传递给组件
constructor(params: RouteParams) {
var dashboardParam= params.get("dashboardParam");
if (dashboardParam) {
...
}
}
这里我有一个路由路径,后跟两个路由参数,路由看起来像 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',
},
]
},
]
},
];
我收到了拒绝的承诺,上面写着 "One of the following must be provided: component, redirectTo, children or loadChildren"。
所以我将 redirectTo: ':dashboardId'
添加到 :dashboardParam
子路由,然后我得到 "Cannot redirect to ':dashboardId'. Cannot find ':dashboardId'."
如何在不出现错误的情况下添加这第三个参数?
实际上你不能写一个没有相应组件去或重定向的路由。你可以这样写
const appRoutes: Routes = [
{
path: 'section/:sectionId',
component: SectionComponent,
children: [
{
path: ':dashboardId/:dashboardParam',
component: DashboardComponent
},
]
},
];
并在组件中检查 dashboardParam
参数是否通过
constructor(params: RouteParams) {
var dashboardParam= params.get("dashboardParam");
if (dashboardParam) {
...
}
}