From c08b3f3c20345605713c0ab47da2c4f601d2dad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Wed, 15 Mar 2017 00:31:57 +0100 Subject: [PATCH] docs: more m.route docs fixes (#1712) --- docs/route.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/route.md b/docs/route.md index 48ed8df4..d5a9c83a 100644 --- a/docs/route.md +++ b/docs/route.md @@ -101,16 +101,26 @@ Argument | Type | Required | Description ##### m.route.link -This function can be used as the `oncreate` hook in a `m("a")` vnode: `m("a[href=/]", {oncreate: m.route.link})`. +This function can be used as the `oncreate` (and `onupdate`) hook in a `m("a")` vnode: + +```JS +m("a[href=/]", {oncreate: m.route.link})`. +``` Using `m.route.link` as a `oncreate` hook causes the link to behave as a router link (i.e. it navigates to the route specified in `href`, instead of nagivating away from the current page to the URL specified in `href`. -`eventHandler = m.route.link(vnode)` +If the `href` attribute is not static, the `onupdate` hook must also be set: + +```JS +m("a", {href: someVariable, oncreate: m.route.link, onupdate: m.route.link})` +``` + +`m.route.link(vnode)` Argument | Type | Required | Description ----------------- | ----------- | -------- | --- -`vnode` | `Vnode` | Yes | This method is meant to be used in conjunction with an `` [vnode](vnodes.md)'s [`oncreate` hook](lifecycle-methods.md) -**returns** | Function(e) | | Returns an event handler that calls `m.route.set` with the link's `href` as the `path` +`vnode` | `Vnode` | Yes | This method is meant to be used as or in conjunction with an `` [vnode](vnodes.md)'s [`oncreate` and `onupdate` hooks](lifecycle-methods.md) +**returns** | | | Returns `undefined` ##### m.route.param