angular - 带参数的角度 10 路由和导航错误
问题描述
路由数组
const routes: Routes = [
...
{path:'exam-list',component: ExamListComponent},
{path:'exam-panel/:Id',component: ExamPanelComponent}
..
];
数组导入
@NgModule({
imports: [RouterModule.forRoot(routes)],
点击事件
onSelect(examdetails)
{
this.router.navigate(['exam-panel',examdetails.Id])
}
点击事件 onselect()
我收到此错误 错误:未捕获(承诺):错误:无法匹配任何路由。 URL段:当我使用routerLink时带有参数的'exam-panel'工作正常,但点击事件无法与router.navigate一起使用
当我使用 [routerLink]="['/exam-panel/',examdetails.Id]" 时,它正在工作,但是当我使用“router.navigate”时,它首先使用参数确定路由考试面板,然后自动路由到主页
解决方案
根据文档https://angular.io/docs/ts/latest/api/router/index/Router-class.html中提到的,您可以使用
导航网址:
router.navigateByUrl(`/exam-panel/${examdetails.Id}`);
或使用导航:
router.navigate(['/exam-panel', examdetails.Id], {relativeTo: route});
相对于调用请求导航到相对于当前 URL 的动态路由路径。
请记住,我们经常忘记/
这是一条相对路线。路由器。导航需要一个 relativeTo 参数来进行相对导航
推荐阅读
- c# - MailKit + .NET Core“发件人地址被拒绝:不归用户所有”错误
- javascript - 使用 jQuery 检查 IP 和端口
- google-cloud-platform - Google Cloud Platform 将 pvc 挂载到实例
- pandas - 是否可以将 Series.str.extract 与 Dask 一起使用?
- pagerduty - 如何通过警报名称设置警报严重性?
- rust - 怎么可能所有闭包都实现“FnOnce”?
- javascript - 在 nuxt vue/typescript 项目中包含 Vue 组件作为节点模块
- vue.js - 如何根据 vue.js 绑定使用 sass 使我的类名动态化?
- c# - Blazor WASM:List.Remove() 调用似乎正在删除对对象的所有引用
- c++ - istringstream 不工作它没有分隔我输入的数字