Fire HashChangeEvent in dart

Issue

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'

Answered By – Günter Zöchbauer

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *