change need
change need

Reputation: 157

URL query string behaves differently

I have routing app routing like below

{
  path: 'services',            
  loadChildren: './services/services-home.module#ServicesHomeModule'
}

and in the service module I have routing like below

{
    path: '',
    component: ServiceHomeComponent
  },
  {
    path: ':slug/:id',
    component: ServiceCategoryComponent,
    pathMatch: 'full',

  },

  {
    path: 'vendor/:id',
    component: VendorAddressComponent,
    pathMatch: 'full'
  }

I'm successfully routing to my ServiceCategoryComponent upto here it is working perfectly.

But when I'm redirecting to VendorAddressComponent, the URL(/services/vendor/10) is successfully changing but where as the component is not loading(but I'm still there in same page)

If suppose if change my routing for ServiceCategoryComponent, to like below

  {
    path: '/sydney/:slug/:id', // if I place any other string instead of sydney it is working fine.
    component: ServiceCategoryComponent,
    pathMatch: 'full',
  }

May I know the what causing weird behaviour? how to rectify this error?

Upvotes: 1

Views: 41

Answers (1)

Bharathkumar kamal
Bharathkumar kamal

Reputation: 211

Route must be reordered as below

{
    path: '',
    component: ServiceHomeComponent
  },
  {
    path: 'vendor/:id',
    component: VendorAddressComponent,
    pathMatch: 'full'
  }
  {
    path: ':slug/:id',
    component: ServiceCategoryComponent,
    pathMatch: 'full',

  }

:slug/:id matches vendor/:id route as well.

Upvotes: 3

Related Questions