angular - 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'
}
我成功地路由到我的ServiceCategoryComponent
upto 这里它工作得很好。
但是当我重定向到时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',
}
我可以知道导致奇怪行为的原因吗?如何纠正这个错误?
解决方案
路线必须重新排序如下
{
path: '',
component: ServiceHomeComponent
},
{
path: 'vendor/:id',
component: VendorAddressComponent,
pathMatch: 'full'
}
{
path: ':slug/:id',
component: ServiceCategoryComponent,
pathMatch: 'full',
}
:slug/:id也匹配vendor/:id路由。
推荐阅读
- sql - Oracle SQL 中的时间戳到日期
- jpa-2.1 - 无法通过 SQL 服务器连接在 JPA 项目上生成实体
- angular - 错误类型错误:this.data 不是函数
- xslt - XSLT:将两个文件复制到一个通用结构中
- php - 从 PHP 到 MYSQL 的最简单更新
- c# - 更改每个平台的 Xamarin Forms 版本 - iOS、Android 和共享
- rdf - 如何将文字值与 rdf 图中的另一个值链接?
- laravel - 如何忽略tinymce中的html标签| Vuejs 和 Laravel
- java - 调用 Zebra 打印机 API 时访问冲突
- node.js - SSR 的 NodeJS 中的 window 对象同时得到“未定义”或“已声明”