Add params: to m.route.Link, fix docs (#2537)

This commit is contained in:
Isiah Meadows 2019-09-30 17:16:24 -04:00 committed by GitHub
parent b98ab29efd
commit 3fa1630f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 4 deletions

View file

@ -218,7 +218,8 @@ module.exports = function($window, mountRedraw) {
child.attrs.onclick = null
} else {
onclick = child.attrs.onclick
href = child.attrs.href
// Easier to build it now to keep it isomorphic.
href = buildPathname(child.attrs.href, child.attrs.params)
child.attrs.href = route.prefix + href
child.attrs.onclick = function(e) {
var result

View file

@ -541,6 +541,36 @@ o.spec("route", function() {
o(route.set.args[2]).equals(opts)
})
o("passes params on route.Link", function() {
var e = $window.document.createEvent("MouseEvents")
e.initEvent("click", true, true)
e.button = 0
$window.location.href = prefix + "/"
route(root, "/", {
"/" : {
view: lock(function() {
return m(route.Link, {
href: "/test",
params: {key: "value"},
})
})
},
"/test" : {
view : lock(function() {
return m("div")
})
}
})
route.set = o.spy(route.set)
root.firstChild.dispatchEvent(e)
o(route.set.callCount).equals(1)
o(route.set.args[0]).equals("/test?key=value")
})
o("route.Link can render without routes or dom access", function() {
$window = browserMock(env)
var render = coreRenderer($window)