Single Page Application router without hash and small

Florian Mertens picture Florian Mertens · Oct 16, 2014 · Viewed 15.6k times · Source

Ok, so I've been googling about this matter for a while now, but I just can't seem to find what I need for a good single-page-application router. What I want:

  1. A jscript router library
  2. A router that does NOT do hashtags/hashbangs
  3. With example.com being my site, that handles something like:
  4. If javascript is disabled, the server returns a valid static html page (helps with search indexing too), with similar internal links, that the server can handle itself <- this part I can do myself
  5. If javascript is enabled, the server returns the same static page, but the router script now prevents links from being clicked, and processes the request itself using eg an anonymous function (as is the case with most router libs), in where I could fill the DOM with dynamic JSON data via javascript.
  6. It handles history correctly.
  7. Is small (I don't want to load an extensive framework when I have my own previously chosen framework already)

Is there a library out there that exists like that? I looked at crossroads.js, which seems great, but it does do hashbangs/hashtags/hashes. I looked at Backbone.js, but with its numerous features and 6.5Kb size, not too keen. This guy had it pretty much on the spot, but his library didn't seem to be well supported. I was pretty amazed at this quick attempt, but it didn't seem to include cross-browser well-enough, or well supported. There are hundreds more out there, but I have no idea which one I should pick? Did anyone else come accross this rather trivial feature for single-page-applications?

Answer

Florian Mertens picture Florian Mertens · Jan 31, 2015

I found Page.

Page is a small client-side routing library for use with building single page applications (SPAs). It has a simple API which is inspired by Express. It utilizes the HTML5 history API under the hood, which is what allows you to build smooth user interfaces while still having linkable URLs for different pages of the app.

Does also do page state caching, which after a good implementation on my end, works really neatly.