Angular: Differentiate between a parameter and child route

211 views Asked by At

I have a situation where, I want a resolver if the child route is a param, and not if it's a path segment. Below is my code.

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

When I hit the path agreement/create, it's throwing error, as create is considered as the value of the param id and it's invalid.

Please help me with this.

1

There are 1 answers

0
asmmahmud On BEST ANSWER

Rearrange your route definition:

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