angular - 如何使角度路由路径“post/:id”和“post/create”共存?
问题描述
我正在使用 Angular 9,这是我的路由部分。
const routes: Routes = [{
path: '',component: PostComponent,
children: [
{ path: '',redirectTo: '',pathMatch: 'full', },
{ path: 'post/:id', component: PostDetailComponent},
{ path: 'post/create', component: PostCreateComponent}
]
}];
当通过路由路径“/post/create”时,初始化的组件实际上是“post/:id”而不是“post/create”,
我该怎么做才能让他们一起工作?
解决方案
路由是基于优先顺序的。所以上面定义的路由将在下面的路由之前匹配。尝试重新排序路由
const routes: Routes = [{
path: '',component: PostComponent,
children: [
{ path: '',redirectTo: '',pathMatch: 'full', },
{ path: 'post/create', component: PostCreateComponent},
{ path: 'post/:id', component: PostDetailComponent}
]
}];
推荐阅读
- c++ - 为什么编译器选项会影响模板实现的选择?
- javascript - PWA 链接 http(s) 依赖项
- jquery - 如何在 jQuery Datatable 中的每个组之后添加分页?
- python - 在 linux 环境中安装底图后,我的 pyart 和 netCDF4 模块无法正常工作。我正在使用 python 3.6.8
- python-3.x - 使用 python3 导出数据时删除 csv 文件中的额外列
- java - 带有条件的 Java 循环
- django - 如何在 django-rest-framework 中制作相关字段的副本
- driver - 在奇异容器中安装驱动程序后,nvidia-smi 无法正常工作
- android-sqlite - 创建表后如何在 SQLite 数据库中设置主键?
- android - 意图服务阻止 UI 并导致 ANR