在路由中传参有3种方法:
1.routerLink
单一参数:在<a routerLink=["/exampledetail",id]>中加routerLink进行跳转,其中/exampledetail是我设置的路由path,id是需要传递的参数。
多个参数:如果要传多个参数,则可以写成routerLink=["/exampledetail",{queryParams:object}] ,queryParams携带多个参数,这个参数的格式可以是自行组织的object,也可以分开多个参数写成routerLink=["/exampledetail",{queryParams:‘id’:‘1’,‘name’:‘yxman’}];。
2.router.navigate
单一参数:this.router.navigate([’/exampledetail’,id]); ,多用在调用方法里
多个参数:this.router.navigate([’/exampledetail’],{queryParams:{‘name’:‘yxman’}});
3.router.navigateByUrl
单一参数:this.router.navigateByUrl(’/exampledetail/id’);
多个参数:this.router.navigateByUrl(’/exampledetail’,{queryParams:{‘name’:‘yxman’}});
传参方传参之后,接收方2种接收方式如下:
1.snapshot
import { ActivateRoute } from ‘@angular/router’;
public data: any;
constructor( public route: Activa
angular路由详解三(路由参数传递)
最新推荐文章于 2022-01-09 14:07:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)