You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Router 3.0.0-beta.2] "data" parameter exists in Route and unable to pass data dynamically #9804
[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.
Reacted by Luke, Mateus Pinheiro, venkateswaris, dmay-work, Matt Heiler, Nik Karbaum, stevenrobijns-macadam, Georgekutty Antony, Manar Kurmanov, Xuan Nguyen and 1 more
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?
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
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.
@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.
@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.
Reacted by Ciprian Tarta, Ramana Murthy , DChappell77, Nik Karbaum, Carlos Roso, Rafael Viero Iop, gopinathsugumar, Neil Arvin Granados, davidsonr, Petyo Cholakov and 1 more
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.
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.
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?
@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?
@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.
Reacted by Tim Fogarty, Christophe GIGAX, Charles Harris, Bogdan Dorca, sashanana, Vijay, neilb01, davidsonr, Arthur Costa, Daniel Pfefferkorn and 3 more
@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.
Activity
zoechi commentedon Jul 4, 2016
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?
ramana-chavakula commentedon Jul 4, 2016
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
zoechi commentedon Jul 4, 2016
I also wasn't able to pass data http://plnkr.co/edit/gIyMenTdIEkC4NajZu4M?p=preview
I don't know if this is supposed to work.
fknop commentedon Jul 4, 2016
Why not use a service for this kind of thing ?
ramana-chavakula commentedon Jul 5, 2016
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
ramana-chavakula commentedon Jul 5, 2016
@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.
zoechi commentedon Jul 5, 2016
similar to #5217
cipriantarta commentedon Jul 5, 2016
@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.
lukeify commentedon Jul 8, 2016
@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
routerLinkseems like an expensive operation, when there could (should) be a way to pass through objects viarouterLinkanyway.2 remaining items
vsavkin commentedon Oct 10, 2016
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.
arvstract commentedon Mar 9, 2017
So ti'll now there is no way to pass data dynamically thru Router.Navigate?
DzmitryShylovich commentedon Mar 9, 2017
@arvstract nope
arvstract commentedon Mar 9, 2017
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.
zoechi commentedon Mar 9, 2017
If you provide the service on a common ancestor component (or directive), then you get the same result.
arvstract commentedon Mar 9, 2017
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?
zoechi commentedon Mar 9, 2017
@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?
altinselimi commentedon Mar 25, 2017
@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.
earshinov commentedon Aug 6, 2018
@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.navigateto be persisted (what is done unconditionally by the History API). So #10248 does not really cover all cases. Please reopen this ticket.earshinov commentedon Aug 6, 2018
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.
andreaslarssen commentedon Sep 5, 2018
+1
jasonaden commentedon Dec 3, 2018
See #27198 for an implementation that supports this.
angular-automatic-lock-bot commentedon Sep 14, 2019
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.