Angular:区分一个参数和子路由

Angular: Differentiate between a parameter and child route

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

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

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

请帮我解决这个问题。

重新排列您的路线定义:

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