Created
January 11, 2016 21:04
-
-
Save augustl/b8a77e6b86028ccaa80f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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