diff --git a/api/router.js b/api/router.js index cf406737..c25ac257 100644 --- a/api/router.js +++ b/api/router.js @@ -54,6 +54,10 @@ module.exports = function($window, redrawService) { route.set(href, undefined, undefined) } } + route.params = function(key) { + if(typeof attrs !== "undefined" && typeof key !== "undefined") return attrs[key] + return attrs + } return route } diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 6a281237..f97fc5db 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -1194,6 +1194,27 @@ o.spec("route", function() { done() }, FRAME_BUDGET * 2) }) + + o("m.route.params is available outside of route handlers", function(done) { + $window.location.href = prefix + "/" + + route(root, "/1", { + "/:id" : { + view : function() { + o(route.params("id")).equals("1") + + return m("div") + } + } + }) + + callAsync(function() { + o(route.params("id")).equals("1") + o(route.params()).deepEquals({id:"1"}) + + done() + }) + }) }) }) })