Enable setting navigation options with m.route.link API
This commit is contained in:
parent
217b9c194c
commit
131e61002e
4 changed files with 50 additions and 9 deletions
|
|
@ -52,7 +52,7 @@ module.exports = function($window, redrawService) {
|
|||
}
|
||||
route.get = function() {return currentPath}
|
||||
route.prefix = function(prefix) {routeService.prefix = prefix}
|
||||
route.link = function(vnode) {
|
||||
var link = function(options, vnode) {
|
||||
vnode.dom.setAttribute("href", routeService.prefix + vnode.attrs.href)
|
||||
vnode.dom.onclick = function(e) {
|
||||
if (e.ctrlKey || e.metaKey || e.shiftKey || e.which === 2) return
|
||||
|
|
@ -60,9 +60,13 @@ module.exports = function($window, redrawService) {
|
|||
e.redraw = false
|
||||
var href = this.getAttribute("href")
|
||||
if (href.indexOf(routeService.prefix) === 0) href = href.slice(routeService.prefix.length)
|
||||
route.set(href, undefined, undefined)
|
||||
route.set(href, undefined, options)
|
||||
}
|
||||
}
|
||||
route.link = function(args) {
|
||||
if (args.tag == null) return link.bind(link, args)
|
||||
return link({}, args)
|
||||
}
|
||||
route.param = function(key) {
|
||||
if(typeof attrs !== "undefined" && typeof key !== "undefined") return attrs[key]
|
||||
return attrs
|
||||
|
|
|
|||
|
|
@ -281,6 +281,36 @@ o.spec("route", function() {
|
|||
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + slash + (prefix ? prefix + "/" : "") + "test")
|
||||
})
|
||||
|
||||
o("passes options on route.link", function() {
|
||||
var opts = {}
|
||||
var e = $window.document.createEvent("MouseEvents")
|
||||
|
||||
e.initEvent("click", true, true)
|
||||
$window.location.href = prefix + "/"
|
||||
|
||||
route(root, "/", {
|
||||
"/" : {
|
||||
view: function() {
|
||||
return m("a", {
|
||||
href: "/test",
|
||||
oncreate: route.link(opts)
|
||||
})
|
||||
}
|
||||
},
|
||||
"/test" : {
|
||||
view : function() {
|
||||
return m("div")
|
||||
}
|
||||
}
|
||||
})
|
||||
route.set = o.spy(route.set)
|
||||
|
||||
root.firstChild.dispatchEvent(e)
|
||||
|
||||
o(route.set.callCount).equals(1)
|
||||
o(route.set.args[2]).equals(opts)
|
||||
})
|
||||
|
||||
o("accepts RouteResolver with onmatch that returns Component", function(done) {
|
||||
var matchCount = 0
|
||||
var renderCount = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue