Skip to content

setUpLocationSync causes an duplicate navigation events #21610

@bourey

Description

@bourey

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions