Skip to content

Instantly share code, notes, and snippets.

@dead-claudia
Last active August 28, 2015 16:24
Show Gist options
  • Save dead-claudia/b8b6f6a4a637c31d9226 to your computer and use it in GitHub Desktop.
Save dead-claudia/b8b6f6a4a637c31d9226 to your computer and use it in GitHub Desktop.
// Uses the m.route.configure plugin in https://gist.github.com/impinball/2e1a78f24f1979f2b7eb
m.route.configure(function () {
return hasLocalStorageToken()
}, function (route) {
return route("/login")
})
m.route = (function (old) {
function check(route) {
if ({}.toString.call(route) !== "[object String]" || hasLocalStorageToken()) {
return old.apply(arguments)
} else {
return old("/login")
}
}
// So the properties are still accessible (and doesn't break Mithril)
for (var i in old) if ({}.hasOwnProperty.call(old, i)) {
check[i] = old[i]
}
return check
})(m.route)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment