Skip to content

[Router 3.0.0-beta.2] "data" parameter exists in Route and unable to pass data dynamically #9804

Closed

Description

@ramana-chavakula

[Router 3.0.0-beta.2] "data" parameter exists in Route and we can pass static data through route definition, but unable to pass dynamic data through RouteLink or navigate method of Router.

Activity

  1. zoechi commented on Jul 4, 2016

    @zoechi
    Contributor

    What is "dynamic data"? How do you want to pass it? What is not working?
    Can you please provide a Plunker that demonstrates what you try to accomplish and what is not working?

  2. ramana-chavakula commented on Jul 4, 2016

    @ramana-chavakula
    Author

    hi zoechi,
    this is my plnkr link: http://plnkr.co/edit/5ATJapZqtV5ieLJx4f2o?p=preview
    In the 'list' route i am just showing the titles of all items in the ListComponent and i want to view individual item in separate route say 'item'.
    I just want to pass the selected item object to 'item' route, which i am not able to find in the documentation

    Thanks in advance

  3. fknop commented on Jul 4, 2016

    @fknop
    Contributor

    Why not use a service for this kind of thing ?

  4. ramana-chavakula commented on Jul 5, 2016

    @ramana-chavakula
    Author

    hey zoechi,
    [routerLink]="['/item', {data: item}] & this.router.navigate(['/item', {data: this.items[index]}]);
    will pass item in Params Object, I already tried that. I think there is no provision for passing data dynamically, so i created an issue

  5. ramana-chavakula commented on Jul 5, 2016

    @ramana-chavakula
    Author

    @fknop : Thanks for responding on this issue.

    It is one of way of solving the problem in setting params before route. this can be done using service as you mentioned in above thread.

    But when we had a data provision to pass as an Object in ui.router where we were expecting similar behaviour in angular2 route which will helps us to communicate between 2 routes without adding data to URL.

    please check the plunker which i drafted for zoechi reply, you will get clear picture on my issue.

  6. zoechi commented on Jul 5, 2016

    @zoechi
    Contributor

    similar to #5217

  7. cipriantarta commented on Jul 5, 2016

    @cipriantarta

    @zoechi, well it's rather a duplicate of #5217.
    Using a service to pass RouteData should be seen as a workaround perhaps. I think that being able to add/merge/replace(with static data) RouteData using the .navigate() or .navigateByUrl() should be a feature that the routing should support. I can't think of a reason not to.

  8. lukeify commented on Jul 8, 2016

    @lukeify

    @fknop I'm also having this issue, and frankly creating an entire service just to pass data between two components which are navigatable to each other via routerLink seems like an expensive operation, when there could (should) be a way to pass through objects via routerLink anyway.

  9. removed their assignment
    on Jul 20, 2016
  10. added
    feature
    and removed on Jul 20, 2016
  11. 2 remaining items

  12. vsavkin commented on Oct 10, 2016

    @vsavkin
    Contributor

    As was pointed out, you can use a shared service to pass the data. After this is implemented #10248, you should be able to set arbitrary data while navigating.

  13. arvstract commented on Mar 9, 2017

    @arvstract

    So ti'll now there is no way to pass data dynamically thru Router.Navigate?

  14. DzmitryShylovich commented on Mar 9, 2017

    @DzmitryShylovich
    Contributor
  15. arvstract commented on Mar 9, 2017

    @arvstract

    Hi @DzmitryShylovich, thank you for the prompt response. Can anyone please explain why they are not supporting it? Is it a bad idea? The problem is I cannot use a Shared service on sibling components unless they are bootstrapped via AppComponent, please correct me if I'm wrong.

  16. zoechi commented on Mar 9, 2017

    @zoechi
    Contributor

    If you provide the service on a common ancestor component (or directive), then you get the same result.

  17. arvstract commented on Mar 9, 2017

    @arvstract

    But isn't it that the ancestor component who initialize the shared service must always be alive so that the shared service instance will continue existing?

  18. zoechi commented on Mar 9, 2017

    @zoechi
    Contributor

    @arvstract depends on what lifetime you want for that service. If the parent component is removed the descendants certainly are. So why would you need to keep the service alive longer than the children that depend on it to share data?

  19. altinselimi commented on Mar 25, 2017

    @altinselimi

    @arvstract No its not a bad idea. Its literally needed in very much any web app scenario when you have to navigate from a list view to a children of that list. Service for this kind of thing is so very stupid.

  20. earshinov commented on Aug 6, 2018

    @earshinov

    @vsavkin , #10248, as you should know as #10248's author, is about setting location state (in terms of browser's History API). In many cases you don't want the data you would pass with router.navigate to be persisted (what is done unconditionally by the History API). So #10248 does not really cover all cases. Please reopen this ticket.

  21. earshinov commented on Aug 6, 2018

    @earshinov

    List of tickets about passing data with router.navigate:

    Currently all the tickets are closed (except #10248 which addressed only a part of the problem), and the issue is still here.

  22. andreaslarssen commented on Sep 5, 2018

    @andreaslarssen

    +1

  23. jasonaden commented on Dec 3, 2018

    @jasonaden
    Contributor

    See #27198 for an implementation that supports this.

  24. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  25. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions