Skip to content

Router navigate with Route Data #5217

Closed

Description

@tbragaf

Is it possible to navigate to an URL and give a json object to it?
As:

// exactly like @RouteConfig
this.router.navigateByUrl('/path', { data: { entity: 'entity' } })

Best regards,
Tiago Braga

Activity

  1. mhevery commented on Nov 15, 2015

    @mhevery
    Contributor

    Not supported. What exactly would you expect to happen?

  2. tbragaf commented on Nov 15, 2015

    @tbragaf
    Author

    I need to navigate to a component and send data to it dynamically.
    So I can't use RouteConfig to do so, right?
    Or I can change the RouteData dynamically?

  3. mhevery commented on Nov 18, 2015

    @mhevery
    Contributor

    @btford can you help?

  4. viperguynaz commented on Dec 31, 2015

    @viperguynaz

    looking to do the same - any help here? other options? Basic problem is parent gets data from an API and needs to send data to child after subscription.

  5. matteosuppo commented on Jan 1, 2016

    @matteosuppo
    Contributor

    Is there a reason why a Service would not be useful in this case?

  6. tbragaf commented on Jan 1, 2016

    @tbragaf
    Author

    @matteosuppo
    I am currently using services to do so, but I always need to implement services to do a simple and must have behaviour. Still I don't like to solve a problem with a workaround.

    Also, what if I refresh the page? The service would lost its state.
    However, with RouteData I can have a default data with the current RouteData implementation, and change it accordingly.

  7. adeteejay commented on Jan 16, 2016

    @adeteejay

    Is there a reason you want to navigate by url why not use the navigate method like this:

    in RouteConf: { path: '/path/:data', name: 'Defined_Path_Name', component: PathComponent }
    navigate with: this.router.navigate(['Defined_Path_Name', { data: { entity: 'entity' } } ]);

    in /path: console.log(this.routeParams.get('data'))
    that got me: Object {entity: "entity"}

  8. mbcooper commented on Mar 4, 2016

    @mbcooper

    NG 1 allowed us to "get" the state object and attach data to it, so we could then pull it off the $state.data object. . In all the examples I have seen, the data on NG2 routes looks to be static.

    How do I attach data in a routeData param dynamically?

  9. tbragaf commented on Mar 4, 2016

    @tbragaf
    Author

    @mbcooper Currently, you don't

  10. cipriantarta commented on Jul 5, 2016

    @cipriantarta

    Is this issue on anyone's radar?
    I have a component which calls for a list of items and when an item is clicked, my router will navigate to the details component. I can pass the item ID to the detail component and use the service to fetch the item, but I'd really like to avoid making a new API call and pass the item to the detail component via .navigate(), fom the list.
    Is this currently possible in any way? RouteParams doesn't work here, because the object has a lot of properties.

  11. mahpah commented on Jul 5, 2016

    @mahpah

    store it in yours service, you don't need to make a new API call

  12. cipriantarta commented on Jul 5, 2016

    @cipriantarta

    @mahpah I was under the impression that a new instance of my service is being created every time the router navigates from one route to another.
    Besides, I think that the service needs to be stateless. One can implement caching on a different layer, but that is another story.

  13. vicb commented on Sep 25, 2016

    @vicb
    Contributor

    related to the old router

  14. cvharris commented on Jun 8, 2017

    @cvharris

    Feel like this was closed very prematurely. I think there's plenty of valid use cases for it

  15. HIMISOCOOL commented on Jun 21, 2017

    @HIMISOCOOL

    It would be great to not have to add another field to a service when all I want to do is know the state of one variable, once, from the previous view, without making the url longer

  16. MattMorrisDev commented on Feb 22, 2018

    @MattMorrisDev

    Yeah, I feel like this is a pretty common use case. I don't need to resolve the data, I already have it. I just want to pass it along to the route I'm navigating to.

    Sure, we can make a service with the sole purpose of being a temporary state holder / transfer-er, but it just feels gross and unnecessary. Yes, paramMap exists, but it tries to serialize everything to the url (which I also don't need in this case), so it can't support complex/nested objects.

  17. FreshTouch commented on Feb 26, 2018

    @FreshTouch
  18. earshinov commented on Aug 6, 2018

    @earshinov

    @hipparch , With all due respect, this feels more like a hack. For a problem that is so common one would expect a supported and well-tested solution built into Angular.

  19. earshinov commented on Aug 6, 2018

    @earshinov

    @vicb, Sure it relates to the old router, but it relates to the current router just as well. Please reopen this ticket. Otherwise another ticket should be opened for the current router.

  20. 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.

  21. andreaslarssen commented on Sep 5, 2018

    @andreaslarssen

    +1

  22. Virendra-Yadav commented on Nov 14, 2018

    @Virendra-Yadav

    looking to do the same - any help here? other options? Basic problem is parent gets data from an API and needs to send data to child after subscription.

    try https://www.npmjs.com/package/ngx-navigation-with-data

  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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions