karthikaruna
karthikaruna

Reputation: 3256

Angular: Differentiate between a parameter and child route

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.

Upvotes: 2

Views: 217

Answers (1)

asmmahmud
asmmahmud

Reputation: 5054

Rearrange your route definition:

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

Upvotes: 3

Related Questions