Make m.route.param() return all params #737

This commit is contained in:
Jakob Dam Jensen 2015-08-18 20:44:58 +02:00
parent 7a5980631e
commit caf1138c31
2 changed files with 24 additions and 0 deletions

View file

@ -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";

View file

@ -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 = "?"