老师,请问angular路由传参可以使用params形式吗?

来源:4-11 路由 URL 和参数 下(3)

会游泳的兔子先森

2020-08-31

就是让传递的参数不显示在url中,就像Vue中的params一样。
比如我需要传递一个base64字符串参数,因为那样太长了。
除了引入storage或者ngrx / redux之类的,请问有解决办法吗

写回答

1回答

接灰的电子产品

2020-08-31

首先 angular 中提倡的是采用 service 传递复杂参数,但路由传递当然也是可能的,通过路由的 state 传递即可

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

然后使用 

constructor(private router: Router) {
  console.log(this.router.getCurrentNavigation().extras.state.example); 
}


0
1
会游泳的兔子先森
非常感谢!
2020-08-31
共1条回复

Angular 开发拼多多webapp 从基础到项目实战

高仿拼多多WebApp,带你在实战环境中学习Angular

1322 学习 · 451 问题

查看课程