Search code examples
dartdart-htmlhashchange

Fire HashChangeEvent in dart


I'm using straight dart:html and I'm looking for a way to fire a HashChangeEvent.

I'm already handling the hash change event:

  window.onHashChange.listen((HashChangeEvent e) {
    hashChange(window.location.hash);
  });

Now I'm looking for a way to change the hash when clicking on a button as example:

querySelector("#some-button").onClick.listen((e) => changeHash("#something"));

All the articles I've found so far shows how to handle the HashChangeEvent.


Solution

  • When you set the hash part of window.location the event is fired.

    window.location.hash = 'something'