angular7 路由跳转传参

this.router.navigate(['action-selection'], { state: { example: 'bar' } });

路由跳转,传入参数。

在目标页面接收参数: 此处需要注意(必须在constructor中获取传参,当从其他地方跳转进页面时,如果没有传参会引起报错。所以需要进行判断)

constructor(
    private http: HttpConfig,
    private commonService: CommonService,
    private notification: NzNotificationService,
    private ActivatedRoute: ActivatedRoute,
    private router: Router
  ) {
    this.searchParams = this.router.getCurrentNavigation().extras["state"]
      ? this.router.getCurrentNavigation().extras["state"]["example"]
      : ""
  }
原文地址:https://www.cnblogs.com/isylar/p/13477438.html