传参

作者: 海货 | 来源:发表于2018-08-05 08:49 被阅读0次

方法一

<a [routerLink]="['/product']" [queryParams]="{id: 1}">Product Details</a>
this.id = routeInfo.snapshot.queryParams['id'];
路径:/product?id=1

方法二

{path: 'product/:id', component: ProductComponent},
<a [routerLink]="['/product', 1]">Product Details</a>
this.id = routeInfo.snapshot.params['id'];
路径:/product/1

有可能的坑

坑1【两个相同组件之间路由,参数不能更新】

办法:使用参数订阅

routeInfo.params.subscribe((params: Params) => this.id = params["id"]);

相关文章

网友评论

      本文标题:传参

      本文链接:https://www.haomeiwen.com/subject/aqnvvftx.html