You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setUpLocationSync causes an duplicate navigation events #21610
Angular's router upgrade code provides a setUpLocationSync method which listens for AngularJS-initiated $locationChangeStart events, then calls Angular's router.navigateByUrl. The docs for this method state that "History.pushState does not fire onPopState, so the Angular location doesn't detect it. The workaround is to attach a location change listener"(
* History.pushState does not fire onPopState, so the Angular location
). Without this code, the Angular router does not respond to location changes initiated by AngularJS, regardless of whether the pages themselves are associated w/ AngularJS or Angular content. For example, AngularJS-based navigation links would fail to trigger a routing event between two Angular pages.
While this code works for AngularJS-initiated location changes, it currently produces duplicate NavigationStart, etc. events for Angular-initiated changes. The AngularJS router sees that the browser location has changed and triggers a location change event, which in turn triggers an additional NavigationStart event in Angular. It appears that we need some way to trigger Angular navigation only for location changes that originate in AngularJS.
This issue is currently causing duplicate router events for any Angular-driven page transition in dual-router apps, which is a performance issue.
Reacted by Anthony Ciccarello, Christopher Mitchell, Juan Pinilla and Klaus Native
I believe I am encountering a related issue where my call to router.navigate() with query params within the ngOnInit() method is being overriden because the $locationChangeStart event is triggering a route back to the same route with no queryParams.
My current workaround is to use setTimeout(fn, 0) to delay the router.navigate() call till after $locationChangeStart.
It is hard to investigate without a reproduction. @bourey, could you create a (preferably minimal 😁) reproduction; either as a repo or a live demo?
In case it helps, here are my stackblitz "playgrounds": ngUpgrade-static, ngUpgrade-lite
@gkalpak It took me about 2 hours to get a concise reproduction but you can see the issue that I'm experiencing in this stackblitz. My example is complicated by some special bootstrapping but I believe the issue should be clearly demonstrated.
Activity
aciccarello commentedon Jan 23, 2018
I believe I am encountering a related issue where my call to
router.navigate()with query params within thengOnInit()method is being overriden because the$locationChangeStartevent is triggering a route back to the same route with no queryParams.My current workaround is to use
setTimeout(fn, 0)to delay therouter.navigate()call till after$locationChangeStart.gkalpak commentedon Jan 23, 2018
It is hard to investigate without a reproduction. @bourey, could you create a (preferably minimal 😁) reproduction; either as a repo or a live demo?
In case it helps, here are my stackblitz "playgrounds": ngUpgrade-static, ngUpgrade-lite
I wonder if this is related to #20244 at all.
@jasonaden, you marked it as a regression. Is there any previous version that is known to work?
aciccarello commentedon Jan 23, 2018
@gkalpak It took me about 2 hours to get a concise reproduction but you can see the issue that I'm experiencing in this stackblitz. My example is complicated by some special bootstrapping but I believe the issue should be clearly demonstrated.
https://stackblitz.com/edit/ajc-angular-upgrade-locationsync-bug
I also tested my stackblitz with Angular versions 4.4.6 and 4.0.3 and the issue remained.
jasonaden commentedon Jan 29, 2018
@gkalpak We thought it was a regression, but as it turns out it had previously been broken. Changing the label.
jasonaden commentedon Jan 29, 2018
Also, this fix (#21728) went in so we can make a change such as this to
upgrade.ts:We are currently testing this change internally to make sure it doesn't open up other issues.
11 remaining items
fix(upgrade): Do not trigger duplicate navigation events from Angular…
fix(upgrade): Do not trigger duplicate navigation events from Angular…
angular-automatic-lock-bot commentedon Mar 5, 2022
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.