Mithril Router
Django style router for Mithril.js
Install
- Download the latest package
- NPM:
npm install mithril-router
Usage
Node.js / Browserify
// Include mithrilvar m = // Pass mithril to the router.// Only required to overload once, subsequent overloads will// return the same instancem
Browser
Documentation
m.route()
Router allowing creation of Single-Page-Applications (SPA) with a DRY mechanism (identification classified as namespaces) to prevent hard-coded URLs.
m.route()
: returns current routem.route(element:DOMElement)
: bind elements while abstracting away route modem.route(namespace|route(, parameters:Object))
: programmatic redirect w/ argumentsm.route(namespace|route(, replaceHistory:Boolean))
: programmatic redirect w/ replacing history entrym.route(namespace|route(, parameters:Object, replaceHistory:Boolean))
: programmatic redirect w/ arguments and replacing history entrym.route(rootElement:DOMElement, routes:Object)
: configure app routingm.route(rootElement:DOMElement, rootRoute:String, routes:Object)
: configure app routing (mithril default router style)
Configure Routing
To define routing specify a host DOM element, and routes with a root route. Should no root route be specified, the first route is chosen.
New
m
Classic
m
m.route.mode
m.route.param()
m.redirect()
Redirect user to specified route, or route namespace with given arguments.
Sugar for m.route(namespace|path(, args))
m.reverse()
Generate path using specified identifier (route namespace) and path arguments.
Api
m.reverse(namespace(, options))
: takes specified route namespace and options and generates path.
Options
-
params
: Object Route parameters, named and non-named. -
query
: String | Object Querystring -
prefix
: String | Boolean Mode, whentrue
prepends the mode char to the route, when defined as a string the string is prepended instead.Useful for when you are not using
config: m.route
Examples
// user => /user/m // user => /user/:id => /user/23m // user => /user/:id => /user/23?include=profilem // user => /user/:id => #/user/23?include=profilemroutemode = 'hash'm // user => /user/:id => /api/user/23?include=profilem
License
Licensed under The MIT License.