如何在angular 项目代码里路由跳转带上参数

102 阅读1分钟

直接看代码

  1. 跳转时带上参数
import { Router } from '@angular/router'

get route() {
    return this.injector.get(Router);
}

this.route.navigate([`admin/orgDashboard/device-repaire`, { type: this.form.data.type, val: this.form.data.val }]);
  1. 在目标页获取参数
import { ActivatedRoute } from '@angular/router'

get activeRoute() {
    return this.injector.get(ActivatedRoute);
}

this.activeRoute.snapshot.paramMap.get('type')
this.activeRoute.snapshot.paramMap.get('val')

这是一份总结。自己手敲一遍记忆更深。

希望对你有帮助。