我在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完全相同?
您将属性subrep.reportID
作为字符串传递,这就是为什么它导航到您看到的结果的原因。试试这个:
<a [routerLink]="['/pages/report/reportdetails', subrep.reportID ]">