URL查询字符串的行为不同

时间:2019-05-21 12:11:07

标签: angular routing

我有如下所示的路由 app routing

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

service module 中,我的路由如下所示

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

  },

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

我已成功路由到我的 ServiceCategoryComponent ,到目前为止,它运行良好。

但是当我重定向到 VendorAddressComponent 时, URL (/ services / vendor / 10)成功更改,但该组件未加载(但我仍在同一页面中)

如果假设将我的 ServiceCategoryComponent, 的路由更改为以下

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

我可以知道是什么引起奇怪的行为吗?如何纠正该错误?

1 个答案:

答案 0 :(得分:3)

路线必须按以下顺序重新排列

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

  }

:slug /:id 也匹配 vendor /:id 路线。