Merge remote-tracking branch 'origin/rewrite' into rewrite
Conflicts: docs/route.md
This commit is contained in:
commit
55f0dfa4dd
16 changed files with 546 additions and 392 deletions
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
- [API](#api)
|
||||
- [Static members](#static-members)
|
||||
- [route.set](#route-set)
|
||||
- [route.get](#route-get)
|
||||
- [route.prefix](#route-prefix)
|
||||
- [route.link](#route-link)
|
||||
- [route.set](#routeset)
|
||||
- [route.get](#routeget)
|
||||
- [route.prefix](#routeprefix)
|
||||
- [route.link](#routelink)
|
||||
- [RouteResolver](#routeresolver)
|
||||
- [routeResolver.onmatch](#routeresolver-onmatch)
|
||||
- [routeResolver.render](#routeresolver-render)
|
||||
- [routeResolver.onmatch](#routeresolveronmatch)
|
||||
- [routeResolver.render](#routeresolverrender)
|
||||
- [How it works](#how-it-works)
|
||||
- [Typical usage](#typical-usage)
|
||||
- [Navigating to different routes](#navigating-to-different-routes)
|
||||
|
|
@ -52,13 +52,13 @@ Argument | Type | Required | Description
|
|||
|
||||
##### route.get
|
||||
|
||||
Returns the current routing path, without the prefix.
|
||||
Returns the last fully resolved routing path, without the prefix. It may differ from the path displayed in the location bar while an asynchronous route is [pending resolution](#code-splitting).
|
||||
|
||||
`path = m.route.get()`
|
||||
|
||||
Argument | Type | Required | Description
|
||||
----------------- | --------- | -------- | ---
|
||||
**returns** | String | | Returns the current path
|
||||
**returns** | String | | Returns the last fully resolved path
|
||||
|
||||
##### route.prefix
|
||||
|
||||
|
|
@ -94,14 +94,12 @@ This method also allows you to asynchronously define what component will be rend
|
|||
|
||||
`routeResolver.onmatch(vnode, resolve)`
|
||||
|
||||
Argument | Type | Description
|
||||
------------------- | --------------------- | ---
|
||||
`vnode` | `Vnode` | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode's `tag` field defaults to a `div`
|
||||
`vnode.attrs` | `Object` | The [routing parameters](#routing-parameters)
|
||||
`vnode.attrs.path` | `String` | The current router path, including interpolated routing parameter values, but without the prefix. Same value as `m.route.get()`
|
||||
`vnode.attrs.route` | `String` | The matched route
|
||||
`resolve` | `Function(Component)` | Call this function with a component as the first argument to use it as the route's component
|
||||
**returns** | | Returns `undefined`
|
||||
Argument | Type | Description
|
||||
--------------- | --------------------- | ---
|
||||
`resolve` | `Function(Component)` | Call this function with a component as the first argument to use it as the route's component
|
||||
`args` | `Object` | The [routing parameters](#routing-parameters)
|
||||
`requestedPath` | `String` | The router path requested by the last routing action, including interpolated routing parameter values, but without the prefix. When `onmatch` is called, the resolution for this path is not complete and `m.route.get()` still returns the previous path.
|
||||
**returns** | | Returns `undefined`
|
||||
|
||||
##### routeResolver.render
|
||||
|
||||
|
|
@ -113,8 +111,6 @@ Argument | Type | Description
|
|||
------------------- | --------------- | -----------
|
||||
`vnode` | `Object` | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode's `tag` field defaults to a `div`
|
||||
`vnode.attrs` | `Object` | A [vnode](vnodes.md) whose attributes object contains routing parameters. If the routeResolver does not have a `resolve` method, the vnode defaults to a `div`
|
||||
`vnode.attrs.path` | `String` | The current router path, including interpolated routing parameter values, but without the prefix. Same value as `m.route.get()`
|
||||
`vnode.attrs.route` | `String` | The matched route
|
||||
**returns** | `Vnode` | Returns a vnode
|
||||
|
||||
---
|
||||
|
|
@ -271,7 +267,7 @@ Instead of mapping a component to a route, you can specify a RouteResolver objec
|
|||
```javascript
|
||||
m.route(document.body, "/", {
|
||||
"/": {
|
||||
onmatch: function(vnode, resolve) {
|
||||
onmatch: function(resolve, args, requestedPath) {
|
||||
resolve(Home)
|
||||
},
|
||||
render: function(vnode) {
|
||||
|
|
@ -351,7 +347,7 @@ var Login = {
|
|||
|
||||
m.route(document.body, "/secret", {
|
||||
"/secret": {
|
||||
onmatch: function(vnode, resolve) {
|
||||
onmatch: function(resolve) {
|
||||
if (isLoggedIn) resolve(Home)
|
||||
else m.route.set("/login")
|
||||
},
|
||||
|
|
@ -399,7 +395,7 @@ function load(file, done) {
|
|||
|
||||
m.route(document.body, "/", {
|
||||
"/": {
|
||||
onmatch: function(vnode, resolve) {
|
||||
onmatch: function(resolve) {
|
||||
load("Home.js", resolve)
|
||||
},
|
||||
},
|
||||
|
|
@ -413,7 +409,7 @@ Fortunately, there are a number of tools that facilitate the task of bundling mo
|
|||
```javascript
|
||||
m.route(document.body, "/", {
|
||||
"/": {
|
||||
onmatch: function(vnode, resolve) {
|
||||
onmatch: function(resolve) {
|
||||
// using Webpack async code splitting
|
||||
require(['./Home.js'], resolve)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue