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.snapshot has old data when route changes

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior ActivatedRoute.snapshot has old data. When route changes, ActivatedRoute.snapshot has data from previous route.

Expected behavior Documentation states that snapshot should be: “The current snapshot of this route.” (https://angular.io/docs/ts/latest/api/router/index/ActivatedRoute-interface.html) Which it is not.

Minimal reproduction of the problem with instructions http://plnkr.co/edit/LThOFFTawaUYg7L9oIXg?p=preview

Click on “First component” in menu and then click on “Increment self” several times.

What is the motivation / use case for changing the behavior? ActivatedRoute.snapshot should have current data even when route changes. It should not be delayed by 1 step.

  • Angular version: 2.1

  • Browser: [Chrome | Firefox | probably all]

  • Language: [TypeScript]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

16reactions
skreborncommented, Nov 16, 2016

As far as I know, ActivatedRoute.params is indeed changed before routing is actually complete. You can subscribe to the actual router events using Router.events, and wait for NavigationEnd. This seems to produce the results you are looking for. See the updated plunker here.

this._router.events.subscribe(event => {
  if (event instanceof NavigationEnd) { 
    // this._activatedRoute.snapshot is up to date
  }
});
10reactions
Alkasihcommented, Nov 29, 2017

This is what I dont like from angular to other SPA, different version, different buil-in function/syntac. Everything change and then new bug waiting for solution again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ActivatedRoute does not update the child route data on route ...
This looked like what I wanted, but didn't work. first run when the childComponent is activated (using routerLink="child" in html) the parent ...
Read more >
Angular Basics: Dynamic Activated Route Snapshots - Telerik
In this post we are going to look into the activated route in Angular and how we can dynamically create and display data...
Read more >
ActivatedRouteSnapshot - Angular
Contains the information about a route associated with a component loaded in an outlet at a particular moment in time. ActivatedRouteSnapshot can also...
Read more >
Angular: ActivatedRoute does not update the child route data ...
I have tried the following example and I'm able to get the data I'm looking for but only for one time. During child...
Read more >
Accessing Route Parameters with ActivatedRoute vs ...
To see the difference between ActivatedRoute and ActivatedRouteSnapshot , we'll make another instance of Router to change the route runtime.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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