From 2de9985a34fc75c02ba733fcaad913199825f0bb Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Wed, 22 Apr 2015 20:45:37 -0400 Subject: [PATCH] throw error if entering infinite redirect loop --- mithril.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index 96e2ff2c..d3430828 100644 --- a/mithril.js +++ b/mithril.js @@ -671,7 +671,7 @@ var m = (function app(window, undefined) { //routing var modes = {pathname: "", hash: "#", search: "?"}; - var redirect = noop, routeParams, currentRoute; + var redirect = noop, routeParams, currentRoute, isDefaultRoute = false; m.route = function() { //m.route() if (arguments.length === 0) return currentRoute; @@ -681,7 +681,10 @@ var m = (function app(window, undefined) { redirect = function(source) { var path = currentRoute = normalizeRoute(source); if (!routeByValue(root, router, path)) { + if (isDefaultRoute) throw new Error("Ensure the default route matches one of the routes defined in m.route") + isDefaultRoute = true m.route(defaultRoute, true) + isDefaultRoute = false } }; var listener = m.route.mode === "hash" ? "onhashchange" : "onpopstate"; @@ -710,7 +713,7 @@ var m = (function app(window, undefined) { element.attachEvent("onclick", routeUnobtrusive) } } - //m.route(route, params) + //m.route(route, params, shouldReplaceHistoryEntry) else if (type.call(arguments[0]) === STRING) { var oldRoute = currentRoute; currentRoute = arguments[0];