为什么路由器链接不起作用,尽管我使用与href相同的组件链接并且它起作用?

问题描述 投票:0回答:1

我在angular 7应用程序上工作,我的问题是使用routerLink时路由无法正常工作但在使用href时有效。

我使href链接具有参数值报告ID

<a href="/pages/report/reportdetails?id={{subrep.reportID}}">

结果工作路线

http://localhost:4200/pages/report/reportdetails?id=3

当在href的相同位置使用路由器链接时,我将执行以下操作:

<a [routerLink]="['/pages/report/reportdetails/id=,subrep.reportID']"> 

结果无法像下面那样生成作为网址的路由

http://localhost:4200/pages/report/reportdetails/id%3D,subrep.reportID

应用程序路由模块:

{path:'report',component:ReportcategoryComponent,children:[
      {path:'reportdetails',component:ReportdetailsComponent},
      {path:'reportdetails/:id',component:ReportdetailsComponent},
      ]},

如何解决问题?

我需要路由器链接使路由与href完全相同?

javascript typescript angular-material angular-components angular7-router
1个回答
0
投票

您将属性subrep.reportID作为字符串传递,这就是为什么它导航到您看到的结果的原因。试试这个:

<a [routerLink]="['/pages/report/reportdetails', subrep.reportID ]"> 
© www.soinside.com 2019 - 2024. All rights reserved.