ActivatedRoute doesn't carry data
See original GitHub issueUPD: Given discussion below, apparently the behavior is what it supposed to be. I am not closing, as there might be some more discussion.
I’m submitting a … [x ] bug report
Current behavior I created a couple of routes with data which I want to use when a router link is clicked:
const routes: Routes =
[
{path: 'run', data: {title: "Runner"}, component: RunComponent},
{path: 'walk', data: {title: "Walker"}, component: WalkComponent}
];
Then in my app I subscribed for ActivatedRoute data to extract the data defined on each route:
constructor(private route: ActivatedRoute) {
}
public ngOnInit() {
this.routeData= this.route.data.subscribe((data) => {
this.name = data.title;
});
}
When I click on the link the data object is empty
Expected behavior I expect the ActivatedRoute to provide data that is defined on the currently active link
Reproduction of the problem See Plunker http://plnkr.co/edit/I62gnvThO0nGN2jk9xhX?p=preview
- Angular version: 2.0.0
- Router version: 3.0.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:16
- Comments:33 (4 by maintainers)
Top Results From Across the Web
Angular 2 - ActivatedRoute don't carry data - Stack Overflow
However, I tried to create another project with the same patterns, but I can't pass data through ActivatedRoute. Here's the code :.
Read more >Router tutorial: tour of heroes - Angular
This tutorial provides an extensive overview of the Angular router. In this tutorial, you build upon a basic router configuration to explore features...
Read more >Angular Routing / Resolve - Load Data before Navigation ...
Imagine a situation where your component template depends upon an array from an API call. And you may have to show a section...
Read more >A word on Angular route resolvers - GitHub Pages
We need to talk about Angular route resolvers. Resolvers are services used by the Angular router to retrieve (asynchronous) data for us during...
Read more >Routing to Angular Material Dialogs | by John Crowson | ngconf
We can also pass data to the dialog component and configure the layout of the ... component's path, access it using ActivatedRoute, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing this issue, as it works as expected.
It doesn’t work @vsavkin , why is it closed.
this.activatedRoute.data.subscribe(res => console.log(res));
It’s logging blank object while I’m passing in data prop in my routes configuration.