路线数据中的角度8路线参数

时间:2019-09-11 09:19:43

标签: angular typescript angular-routing angular8

我有以下路线:

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

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

1 个答案:

答案 0 :(得分:2)

我不确定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的使用作为一个函数来调用,而不仅仅是使用对象属性。