首页 > 解决方案 > URL 查询字符串的行为不同

问题描述

我有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'
  }

我成功地路由到我的ServiceCategoryComponentupto 这里它工作得很好。

但是当我重定向到时VendorAddressComponentURL(/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',
  }

我可以知道导致奇怪行为的原因吗?如何纠正这个错误?

标签: angularrouting

解决方案


路线必须重新排序如下

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

  }

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


推荐阅读