feat: bring back m.route.params()

Because it's annoying only having route params available to the
top-level components within a route.
This commit is contained in:
Pat Cavit 2017-01-11 14:23:42 -08:00
parent 68f832d776
commit 834dd02610
2 changed files with 25 additions and 0 deletions

View file

@ -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
}

View file

@ -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()
})
})
})
})
})