Skip to content

Instantly share code, notes, and snippets.

@augustl
Created January 11, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save augustl/b8a77e6b86028ccaa80f to your computer and use it in GitHub Desktop.
Save augustl/b8a77e6b86028ccaa80f to your computer and use it in GitHub Desktop.
var APP_ROUTES = (function () {
function appRoutesCreate(notFoundHandler) {
var r = Rlite();
function transitionTo(path) {
document.location.hash = path;
}
function transitionToReplace(path) {
document.location.replace("#" + path);
}
return {
transitionTo: transitionTo,
transitionToReplace: transitionToReplace,
on: function (path, handler) {
r.add(path.slice(1), function (r) { handler(r.params); });
},
run: function () {
function processHash() {
var hash = location.hash || '#';
var found = r.run(hash.slice(1));
if (!found) {
notFoundHandler();
}
}
window.addEventListener('hashchange', processHash);
processHash();
}
}
}
return {
create: appRoutesCreate
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment