方法一
<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"]);
网友评论