angular - 以角度 6 在路由中传递两个参数
问题描述
我正在通过路由传递两个参数,但它不起作用。当我点击 routerLink 时,它会将我重定向到我的默认路由。
表示没有接受参数的路由。
我错过了什么..?
提前致谢。
路径是:
{path:'Buy/:term1/:term2', component: Buycomponent}
我正在传递这样的参数:
<a [routerLink] ="['/Buy',{term1:'sale',term2:'home'}]">data</a>
在组件中我得到这样的参数:
this.route.params.subscribe(response => console.log(response.term1 , responce.term2));
.
更新...
对于单一值,它工作正常。
{path:'Buy/:term1, component: Buycomponent}
并像这样传递参数:
<a [routerLink] ="['/Buy','sale']">data</a>
在组件中我得到这样的参数:
this.route.params.subscribe(response => console.log(response.term1));
解决方案
尝试这个:
<a [routerLink] ="['/Buy','sale','home']">data</a>
当您想要传递可选参数时使用此语法
<a [routerLink] ="['/Buy',{term1:'sale',term2:'home'}]">data</a>
推荐阅读
- python - 在pygame中绘制非像素化圆圈
- php - 在php中通过空格读取字符串
- python - 调试嵌入式 pybind11 python 解释器
- javascript - 创建一个由拾取的对象属性组成的对象:
- angular - 无法使用角度订阅转移价值
- excel - 用vba排序
- c# - 如何在asp.net core 3.1中从open-api doc做深度对象的模型绑定
- google-apps-script - 谷歌应用脚本从谷歌文档中查找关键文本旁边的文本
- java - 在使用 Quarkus Hibernate Reactive 和 quarkus-reactive-client 时如何使用一些阻塞方法?
- android - 带有圆形边缘的不确定 ProgressBar