cerebral / addressbar

Makes the addressbar of the browser work just like a normal input
MIT License
84 stars 8 forks source link

addressbar change event fires twice on <a> tag #18

Closed awei01 closed 7 years ago

awei01 commented 7 years ago

When an <a> tag with href changes url, the addressbar.on('change') fires twice.

Here's a repo I created to replicate issue: https://github.com/awei01/addressbar-test

Tested on firefox and chrome.

christianalfoni commented 7 years ago

Ah, yes, "correct behaviour" is a bit difficult to define :)

To make it work as you expect you always have to:

addressbar.on('change', (event) => {
  event.preventDefault()
})

This is the code that takes control of the addressbar.

It is a while since I wrote the code, but I believe change is hooked up to both a href clicks and pushState events... to be able to prevent a href clicks it needs to listen to those clicks, but it also needs to listen to pushState events to handle them as well. So yeah... might be a way to make this more predictable though

awei01 commented 7 years ago

Ok, thanks for the response.