Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: Why does HashLocationStrategy listen to popState and hashChange events? #7908

Closed
matanlurey opened this issue Apr 4, 2016 · 2 comments

Comments

@matanlurey
Copy link
Contributor

Steps to reproduce and a minimal demo of the problem

View hash_location_strategy:

  void onPopState(UrlChangeListener fn) {
    this._platformLocation.onPopState(fn);
    this._platformLocation.onHashChange(fn);
  }

Internal clients rely on manually dispatching window.hashchange events in order to have other libraries that rely on listening to hashchange manually know what the route is. Unfortunately, this seems to cause duplicate routing now.

A workaround is to override HashLocationStrategy and replace:

@override
  void onPopState(UrlChangeListener fn) {
    // Instead of listening to hashChange + popState, just listen to hashChange.
    //
    // We manually invoke hashChange events which can cause duplicate routing.
    _platformLocation.onPopState(fn);
  }

I'd prefer not to keep it like that long-term.

Current behavior

Listens to both type of events.

Expected/desired behavior

I'd imagine listen to just one?

@vsavkin
Copy link
Contributor

vsavkin commented Jul 13, 2016

Closed here #10011

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants