通过 Angular 中的路由路径发送数据 [英] Send data through routing paths in Angular
问题描述
有没有将数据作为参数与 router.navigate 一起发送?我的意思是,类似于
2) 路由可选参数:
3) 路由查询参数:
4) 您可以使用服务将数据从一个组件传递到另一个组件,而根本不使用路由参数.
示例参见:https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/
我在这里有一个 plunker:https://plnkr.co/edit/KT4JLmpcwGBM2xdZQeI9?p=预览
Is there anyway to send data as parameter with router.navigate? I mean, something like this example, as you can see the route has a data parameter, but doing this it's not working:
this.router.navigate(["heroes"], {some-data: "othrData"})
because some-data is not a valid parameter. How can I do that? I don't want to send the parameter with queryParams.
There is a lot of confusion on this topic because there are so many different ways to do it.
Here are the appropriate types used in the following screen shots:
private route: ActivatedRoute
private router: Router
1) Required Routing Parameters:
2) Route Optional Parameters:
3) Route Query Parameters:
4) You can use a service to pass data from one component to another without using route parameters at all.
For an example see: https://blogs.msmvps.com/deborahk/build-a-simple-angular-service-to-share-data/
I have a plunker of this here: https://plnkr.co/edit/KT4JLmpcwGBM2xdZQeI9?p=preview
这篇关于通过 Angular 中的路由路径发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!