我有如下所示的路由 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',
}
我可以知道是什么引起奇怪的行为吗?如何纠正该错误?
答案 0 :(得分:3)
路线必须按以下顺序重新排列
{
path: '',
component: ServiceHomeComponent
},
{
path: 'vendor/:id',
component: VendorAddressComponent,
pathMatch: 'full'
}
{
path: ':slug/:id',
component: ServiceCategoryComponent,
pathMatch: 'full',
}
:slug /:id 也匹配 vendor /:id 路线。