Skip to content
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

Closed
ramana-chavakula opened this issue Jul 4, 2016 · 23 comments
Labels
area: router feature Issue that requests a new feature

Comments

@ramana-chavakula
Copy link

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

@zoechi
Copy link
Contributor

zoechi commented 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
Copy link
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

@zoechi
Copy link
Contributor

zoechi commented 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
Copy link
Contributor

fknop commented Jul 4, 2016

Why not use a service for this kind of thing ?

@ramana-chavakula
Copy link
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

@ramana-chavakula
Copy link
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.

@zoechi
Copy link
Contributor

zoechi commented Jul 5, 2016

similar to #5217

@cipriantarta
Copy link

@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
Copy link

lukeify commented 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 routerLink seems like an expensive operation, when there could (should) be a way to pass through objects via routerLink anyway.

@vsavkin vsavkin removed their assignment Jul 20, 2016
@vsavkin vsavkin added feature Issue that requests a new feature area: router and removed area: router labels Jul 20, 2016
@lanocturne
Copy link

At 3.0.0-rc.2 the data snapshot is always empty.
i.e.

 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

@vsavkin
Copy link
Contributor

vsavkin commented 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.

@vsavkin vsavkin closed this as completed Oct 10, 2016
@arvstract
Copy link

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

@DzmitryShylovich
Copy link
Contributor

@arvstract nope

@arvstract
Copy link

arvstract commented 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
Copy link
Contributor

zoechi commented Mar 9, 2017

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

@arvstract
Copy link

arvstract commented 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
Copy link
Contributor

zoechi commented 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
Copy link

@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
Copy link

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

@earshinov
Copy link

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
Copy link

+1

@jasonaden
Copy link
Contributor

See #27198 for an implementation that supports this.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: router feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests