Send data through routing paths in Angular

前端 未结 6 1289
无人共我
无人共我 2020-11-22 08:52

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

6条回答
  •  抹茶落季
    2020-11-22 09:36

    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

提交回复
热议问题