Angular:区分参数和子路由

时间:2017-10-14 00:47:42

标签: angular angular2-routing angular2-router angular2-resolve

我有一种情况,如果子路由是一个参数,我想要一个解析器,而不是它是一个路径段。以下是我的代码。

{
    path: 'agreement',
    children: [
      {
        path: ':id',
        component: AgreementComponent,
        resolve: { agreementDetails: AgreementDetailsResolveService }
      },
      {
        path: 'create',
        component: AgreementComponent
      }
    ]
  }

当我点击路径agreement/create时,它会抛出错误,因为create被视为参数id的值而且无效。

请帮助我。

1 个答案:

答案 0 :(得分:1)

重新排列路线定义:

{
    path: 'agreement',
    children: [
      {
        path: 'create',
        component: AgreementComponent
      },
      {
        path: ':id',
        component: AgreementComponent,
        resolve: { agreementDetails: AgreementDetailsResolveService }
      }
    ]
  }