document new argument in m.route(path)

This commit is contained in:
Leo Horie 2014-05-25 23:52:46 -04:00
parent 2b8c82e365
commit bdcfbde8e0
5 changed files with 19 additions and 12 deletions

View file

@ -5,6 +5,8 @@
### News: ### News:
- The signature of `m` now accepts virtual elements as the second parameter of the function. - The signature of `m` now accepts virtual elements as the second parameter of the function.
- `m.route(path, params)` now accepts an argument that gets parsed as a querystring.
- routes now ignore trailing slashes [#88](https://github.com/lhorie/mithril.js/issues/88)
### Bug Fixes: ### Bug Fixes:

View file

@ -37,7 +37,7 @@
<li><a href="mithril.route.html">m.route</a> <li><a href="mithril.route.html">m.route</a>
<ul> <ul>
<li><a href="mithril.route.html#defining-routes">m.route(rootElement, defaultRoute, routes)</a></li> <li><a href="mithril.route.html#defining-routes">m.route(rootElement, defaultRoute, routes)</a></li>
<li><a href="mithril.route.html#redirecting">m.route(path)</a></li> <li><a href="mithril.route.html#redirecting">m.route(path, params)</a></li>
<li><a href="mithril.route.html#reading-current-route">m.route()</a></li> <li><a href="mithril.route.html#reading-current-route">m.route()</a></li>
<li><a href="mithril.route.html#mode-abstraction">m.route(element)</a></li> <li><a href="mithril.route.html#mode-abstraction">m.route(element)</a></li>
<li><a href="mithril.route.html#mode">m.route.mode</a></li> <li><a href="mithril.route.html#mode">m.route.mode</a></li>

View file

@ -264,13 +264,17 @@ redirects to `http://server/#/dashboard/marysue`
[How to read signatures](how-to-read-signatures.md) [How to read signatures](how-to-read-signatures.md)
```clike ```clike
void route(String path) void route(String path [, any params])
``` ```
- **String path** - **String path**
The route to redirect to. Note that to redirect to a different page outside of the scope of Mithril's routing, you should use `window.location` The route to redirect to. Note that to redirect to a different page outside of the scope of Mithril's routing, you should use `window.location`
- **any params**
Parameters to pass as a querystring
--- ---
<a name="reading-current-route"></a> <a name="reading-current-route"></a>

14
mithril.d.ts vendored
View file

@ -6,13 +6,13 @@ interface MithrilStatic {
prop(value?: any): (value?: any) => any; prop(value?: any): (value?: any) => any;
withAttr(property: string, callback: (value: any) => void): (e: Event) => any; withAttr(property: string, callback: (value: any) => void): (e: Event) => any;
module(rootElement: Element, module: MithrilModule): void; module(rootElement: Element, module: MithrilModule): void;
trust(html: string): String trust(html: string): String;
render(rootElement: Element, children?: any): void render(rootElement: Element, children?: any): void;
render(rootElement: HTMLDocument, children?: any): void render(rootElement: HTMLDocument, children?: any): void;
redraw(): void redraw(): void;
route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
route(path: string): void route(path: string, params?: any, shouldReplaceHistory?: boolean): void;
route(): string; route(): string;
route(element: Element, isInitialized: boolean): void; route(element: Element, isInitialized: boolean): void;
request(options: MithrilXHROptions): MithrilPromise; request(options: MithrilXHROptions): MithrilPromise;

View file

@ -298,9 +298,10 @@ Mithril = m = new function app(window) {
} }
else if (typeof arguments[0] == "string") { else if (typeof arguments[0] == "string") {
currentRoute = arguments[0] currentRoute = arguments[0]
var shouldReplaceHistoryEntry = arguments[1] === true var querystring = typeof arguments[1] == "object" ? buildQueryString(arguments[1]) : null
var queryString = typeof arguments[1] == "object" ? buildQueryString(arguments[1]) : null if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring
if(queryString) currentRoute += (currentRoute.indexOf('?') === -1 ? '?' : '&') + queryString
var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true
if (window.history.pushState) { if (window.history.pushState) {
computePostRedrawHook = function() { computePostRedrawHook = function() {