Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度10路由和;带参数的导航错误_Angular_Angular Routing_Angular10 - Fatal编程技术网

Angular 角度10路由和;带参数的导航错误

Angular 角度10路由和;带参数的导航错误,angular,angular-routing,angular10,Angular,Angular Routing,Angular10,路由阵列 const routes: Routes = [ ... {path:'exam-list',component: ExamListComponent}, {path:'exam-panel/:Id',component: ExamPanelComponent} .. ]; 导入的数组 @NgModule({ imports: [RouterModule.forRoot(routes)], 点击事件 onSelect(examdetails) { this.rou

路由阵列

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时,它可以正常工作,但单击事件不适用于router.navigate

当我使用[routerLink]=“['/exam panel/”,examdetails.Id]”时,它工作正常,但当我使用“router.navigate”时,它会使用参数ok导航第一个路由考试面板,然后根据文档中提到的自动路由到主页,您可以使用

导航菜单:

router.navigateByUrl(`/exam-panel/${examdetails.Id}`);
或使用导航:

router.navigate(['/exam-panel', examdetails.Id], {relativeTo: route});
相对于调用请求导航到相对于当前URL的动态路由路径


请记住,我们经常忘记这是一条相对路线。路由器。navigate需要相对导航的relativeTo参数

router.navigateByUrl(
/exam panel/${examdetails.Id}
)?你的考试详情是什么?身份证来了吗?你控制台记录了吗?examdetails是一个json数组,来自API HTTP请求当我使用[routerLink]=“['/exam panel/',examdetails.Id]”时,它可以工作,但当我使用“router.navigate”时,它会naviagte第一个路由检查面板,参数为ok,然后自动路由到主页路由器。navigate(['/exam panel',examdetails.Id],{relativeTo:route});你试过在考试面板前的router.navgate中添加“/”吗?{relativeTo:route}你能给我解释一下什么是“route”吗