visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 688 forks source link

Attaching onpopstate to hashchange? #273

Open DanielMiddleton opened 9 years ago

DanielMiddleton commented 9 years ago

I ran into a bug this afternoon where some of my routes weren't working in IE (10 and 11). We're using hashes for certain in-page routes (not hashbangs though), to trigger loading certain overlays. The route would get populated but the content wouldn't be shown, because the onpopstate event was not fired, because it was only a hash change.

Attaching onpopstate to the hashchange event in page.start resolves my issue:

if (false !== options.hashChange) window.addEventListener('hashchange', onpopstate, false); 

Is a particular reason this doesn't already exist, or something else that I should be doing instead?

davidhirtz commented 8 years ago

You have saved my life, bro! This needs to be implemented asap! +1

jonvuri commented 7 years ago

This needs to be fixed! In addition, it seems that both the click handler and popstate handlers are firing for hash-only (href="#hash") routes in IE11, causing buggy behavior where the path seems to be reset.

matthewp commented 6 years ago

Are you saying you have a route like:

page('/about#me', function(){
  // do stuff here
});

And this is not triggered because we don't listen for the hashchange?

matthewp commented 6 years ago

Just a small update, I looked into this yesterday and adding that event listener broke some other tests. I didn't have a chance to look into why it breaks those tests. My guess is that since we already listening to anchor click events, we might get double events when also listening to hashchange. This is just a guess though. I'm writing this as a note to myself when I get the chance to look at this issue again.