question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ActivatedRoute doesn't carry data

See original GitHub issue

UPD: 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:closed
  • Created 7 years ago
  • Reactions:16
  • Comments:33 (4 by maintainers)

github_iconTop GitHub Comments

46reactions
vsavkincommented, Oct 4, 2016

Closing this issue, as it works as expected.

23reactions
paramsingh88commented, Aug 1, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found