From caf1138c314d6e1b4a7608109ad745d7faf2b6c7 Mon Sep 17 00:00:00 2001 From: Jakob Dam Jensen Date: Tue, 18 Aug 2015 20:44:58 +0200 Subject: [PATCH] Make m.route.param() return all params #737 --- mithril.js | 3 +++ tests/mithril-tests.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/mithril.js b/mithril.js index 3bcde247..58760547 100644 --- a/mithril.js +++ b/mithril.js @@ -958,6 +958,9 @@ var m = (function app(window, undefined) { }; m.route.param = function(key) { if (!routeParams) throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()"); + if( !key ){ + return routeParams; + } return routeParams[key]; }; m.route.mode = "search"; diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 8967c268..05b6be20 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -2579,6 +2579,27 @@ function testMithril(mock) { return result }) + test(function() { // test route params returning params object if no key is given + mock.requestAnimationFrame.$resolve() //setup + + var root = mock.document.createElement("div") + m.route.mode = "search" + m.route(root, "/", { + "/": {controller: function() {}, view: function() {}}, + "/test12": {controller: function() {}, view: function() {}} + }) + mock.requestAnimationFrame.$resolve() + m.route("/test12", {a: "foo", b: "bar"}) + mock.requestAnimationFrame.$resolve() + + var params = m.route.param(); + + var result = params.a === "foo" && params.b === "bar" + + m.mount(root, null) //teardown + + return result + }) test(function() { mock.requestAnimationFrame.$resolve() //setup mock.location.search = "?"