Add more docs around m.route (#1089)

This commit is contained in:
Pat Cavit 2016-06-03 11:33:46 -07:00
parent ca784a684e
commit d05b155abc

View file

@ -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"
}
}
});
```