Last active
August 28, 2015 16:24
-
-
Save dead-claudia/b8b6f6a4a637c31d9226 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Uses the m.route.configure plugin in https://gist.github.com/impinball/2e1a78f24f1979f2b7eb | |
m.route.configure(function () { | |
return hasLocalStorageToken() | |
}, function (route) { | |
return route("/login") | |
}) |
This file contains hidden or 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
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