New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Router 3.0.0-beta.2] "data" parameter exists in Route and unable to pass data dynamically #9804
Comments
What is "dynamic data"? How do you want to pass it? What is not working? |
hi zoechi, Thanks in advance |
I also wasn't able to pass data http://plnkr.co/edit/gIyMenTdIEkC4NajZu4M?p=preview |
Why not use a service for this kind of thing ? |
hey zoechi, |
@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. |
similar to #5217 |
@zoechi, well it's rather a duplicate of #5217. |
@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 |
At 3.0.0-rc.2 the data snapshot is always empty. Route: {
path: "test",
component: TestComp,
**data**: {
title: 'test title'
}
} At TestComp component or directive, log it from ActivatedRoute this.route.data.subscribe(data=> console.log(data));
console.log(this.route.snapshot.data["title"]); The result would be {} and undefined |
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. |
So ti'll now there is no way to pass data dynamically thru Router.Navigate? |
@arvstract nope |
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. |
If you provide the service on a common ancestor component (or directive), then you get the same result. |
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. |
@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 |
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. |
+1 |
See #27198 for an implementation that supports this. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
[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.
The text was updated successfully, but these errors were encountered: