TehShrike / noddity

It's a blog, it's a wiki, it's a fast CMS!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use the history API

ArtskydJ opened this issue · comments

What do you think about using the history API after static rendering (#30) is completed?

The history API is 80% supported, and anyone without it could fall back to http requests.

See ponyfoo/stop-breaking-the-web.

The obvious downside being, that hashbang urls that are in use right now would have to be supported, or redirected to the correct page.

I would have used the history API from the beginning, except that it doesn't fire an onhashchange equivalent when you click on a link.

popstate doesn't fire when you click on a link, so we would also have to implement some kind of hack to make all links not actually visit the link that they pointed to, and fiddle with the history manually in those cases.

Related: TehShrike/abstract-state-router#48

popstate doesn't fire when you click on a link because that's not how the History API works. If you want the link to modify the history programmatically you have to preventDefault() and then fire an equivalent pushState.

Either that or, on page load, use replaceState with that page's location.pathname

What event is fired when you click on a link where you can call event.preventDefault() and cancel the regular navigation to that other page?

Yeah, watching for all click events and doing magical things when the clicked thing happens to be a link is the only way I know of too.

I wouldn't call it 'magic', it's simply a different kind of navigation

Well, handling all click events and adding non-standard behavior to core browser behavior (what happens when you click on a elements) is a bit more magical than I usually roll. Not that it's inappropriate.

I'm going to close this for now, but the idea will be implemented eventually when we start working on the static-server support for Noddity.