Add params: to m.route.Link, fix docs (#2537)
This commit is contained in:
parent
b98ab29efd
commit
3fa1630f91
4 changed files with 38 additions and 4 deletions
|
|
@ -218,7 +218,8 @@ module.exports = function($window, mountRedraw) {
|
||||||
child.attrs.onclick = null
|
child.attrs.onclick = null
|
||||||
} else {
|
} else {
|
||||||
onclick = child.attrs.onclick
|
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.href = route.prefix + href
|
||||||
child.attrs.onclick = function(e) {
|
child.attrs.onclick = function(e) {
|
||||||
var result
|
var result
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,36 @@ o.spec("route", function() {
|
||||||
o(route.set.args[2]).equals(opts)
|
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() {
|
o("route.Link can render without routes or dom access", function() {
|
||||||
$window = browserMock(env)
|
$window = browserMock(env)
|
||||||
var render = coreRenderer($window)
|
var render = coreRenderer($window)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
- This is unlikely to break people because if you were to do it with `m.render` directly before now, you'd corrupt Mithril's internal representation and internal errors could occur as a result. Now, it just warns you.
|
- This is unlikely to break people because if you were to do it with `m.render` directly before now, you'd corrupt Mithril's internal representation and internal errors could occur as a result. Now, it just warns you.
|
||||||
- For a better debugging experience with `m.route` route resolvers, errors on `onmatch` in the default route are left unhandled and errors in `onmatch` in other routes are logged to the console before redirecting. ([#2536](https://github.com/MithrilJS/mithril.js/pull/2536) [@isiahmeadows](https://github.com/isiahmeadows))
|
- For a better debugging experience with `m.route` route resolvers, errors on `onmatch` in the default route are left unhandled and errors in `onmatch` in other routes are logged to the console before redirecting. ([#2536](https://github.com/MithrilJS/mithril.js/pull/2536) [@isiahmeadows](https://github.com/isiahmeadows))
|
||||||
- Bug fix with `m.redraw` where if you removed a root that was previously visited in the current redraw pass, it would lose its place and skip the next root.
|
- Bug fix with `m.redraw` where if you removed a root that was previously visited in the current redraw pass, it would lose its place and skip the next root.
|
||||||
|
- Add `params:` attribute to `m.route.Link`. ([#2537](https://github.com/MithrilJS/mithril.js/pull/2537) [@isiahmeadows](https://github.com/isiahmeadows))
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ m(m.route.Link, {
|
||||||
// first parameter to `m`.
|
// first parameter to `m`.
|
||||||
selector: "span",
|
selector: "span",
|
||||||
options: {replace: true},
|
options: {replace: true},
|
||||||
|
params: {key: "value"},
|
||||||
href: "/test",
|
href: "/test",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
class: "nav-link",
|
class: "nav-link",
|
||||||
|
|
@ -201,9 +202,10 @@ Do note that this doesn't also disable pointer events for you - you have to do t
|
||||||
Argument | Type | Required | Description
|
Argument | Type | Required | Description
|
||||||
--------------------- | ------------------------------------ | -------- | ---
|
--------------------- | ------------------------------------ | -------- | ---
|
||||||
`attributes.href` | `Object` | Yes | The target route to navigate to.
|
`attributes.href` | `Object` | Yes | The target route to navigate to.
|
||||||
`attributes.selector` | `String|Object|Function` | No | This sets the tag name to use. Must be a valid selector for [`m`](hyperscript.md) if given, defaults to `"a"`.
|
`attributes.selector` | `String|Object|Function` | No | This sets the tag name to use. Must be a valid selector for [`m`](hyperscript.md) if given, defaults to `"a"`.
|
||||||
`attributes.options` | `Object` | No | This sets the options passed to [`m.route.set`](#mrouteset).
|
`attributes.options` | `Object` | No | This sets the options passed to [`m.route.set`](#mrouteset).
|
||||||
`attributes.disabled` | `Object` | No | This sets the options passed to [`m.route.set`](#mrouteset).
|
`attributes.params` | `Object` | No | This sets the parameters passed to [`m.route.set`](#mrouteset).
|
||||||
|
`attributes.disabled` | `Object` | No | This disables the link, so clicking on it doesn't route anywhere.
|
||||||
`attributes` | `Object` | No | Other attributes to apply to the returned vnode may be passed.
|
`attributes` | `Object` | No | Other attributes to apply to the returned vnode may be passed.
|
||||||
`children` | `Array<Vnode>|String|Number|Boolean` | No | Child [vnodes](vnodes.md) for this link.
|
`children` | `Array<Vnode>|String|Number|Boolean` | No | Child [vnodes](vnodes.md) for this link.
|
||||||
**returns** | `Vnode` | | A [vnode](vnodes.md).
|
**returns** | `Vnode` | | A [vnode](vnodes.md).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue