diff --git a/docs/v1.x-migration.md b/docs/v1.x-migration.md index 8bb02eff..f5617d06 100644 --- a/docs/v1.x-migration.md +++ b/docs/v1.x-migration.md @@ -9,6 +9,8 @@ Migrating from `v0.2.x` to `v1.x` - [Component arguments](#component-arguments) - [Passing components to `m()`](#passing-components-to-m) - [`m.route` and anchor tags](#mroute-and-anchor-tags) +- [Reading/writing the current route](#readingwriting-the-current-route) +- [Accessing route params](#accessing-route-params) ## `config` function @@ -197,3 +199,58 @@ m("a", { oncreate : m.route.link }) ``` + +## Reading/writing the current route + +In `v0.2.x` all interaction w/ the current route happened via `m.route()`. In `v1.x` this has been broken out into two functions. + +### `v0.2.x` + +```js +// Getting the current route +m.route() + +// Setting a new route +m.route("/other/route"); +``` + +### `v1.x` + +```js +// Getting the current route +m.route.getPath(); + +// Setting a new route +m.route.setPath("/other/route"); +``` + +## Accessing route params + +In `v0.2.x` reading route params was all handled through the `m.route.param()` method. In `v1.x` any route params are passed as the `attrs` object on the vnode passed as the first argument to lifecycle methods/`view`. + +### `v0.2.x` + +```js +m.route(document.body, "/booga", { + "/:attr" : { + view : function() { + m.route.param("attr"); // "booga" + } + } +}); +``` + +### `v1.x` + +```js +m.route(document.body, "/booga", { + "/:attr" : { + oninit : function(vnode) { + vnode.attrs.attr; // "booga" + }, + view : function(vnode) { + vnode.attrs.attr; // "booga" + } + } +}); +```