Angular 路由数据中有 8 个路由参数

Angular 8 route params in route data

我有以下路线:

{
path: 'introducer/:introducerId/branches/create',
component: IntroducerBranchesCreateComponent,
data: {
  pageTitle: 'Add branch',
  breadcrumbs: [
    { title: 'Branches', link: '/introducer/' + :introducerId + '/branches' },
    { title: 'Add', link: '' },
  ],
},
},

在面包屑数组中,我想使用路由参数 :introducerId 填充 link 属性,但无法这样做。有办法吗?

我不是 100% 确定这是否可行,但您可以尝试一下

{
    path: 'introducer/:introducerId/branches/create',
    component: IntroducerBranchesCreateComponent,
    data: {
        pageTitle: 'Add branch',
        breadcrumbs: () => {
            const id = this.getIntroducerId();

            return [
                { title: 'Branches', link: `/introducer/${id}/branches` },
                { title: 'Add', link: '' },
            ]
        }
    },
}

然后将方法 getIntroducerId 添加到您的组件,并使您对 data.breadcrumbs 的使用将其作为函数调用,而不是仅使用对象 属性.