mithril-router

所属分类:后台框架
开发工具:JavaScript
文件大小:10KB
下载次数:0
上传日期:2016-01-06 21:31:33
上 传 者sh-1993
说明:  用于Mithril.js的Django风格路由器
(Django style router for Mithril.js)

文件列表:
.jshintrc (738, 2016-01-07)
.travis.yml (126, 2016-01-07)
LICENSE (1103, 2016-01-07)
Makefile (539, 2016-01-07)
mithril.router.js (11877, 2016-01-07)
package.json (558, 2016-01-07)
test (0, 2016-01-07)
test\mithril.router.js (15275, 2016-01-07)

# Mithril Router Django style router for [Mithril.js][mithril] [![version][npm-version]][npm-url] [![License][npm-license]][license-url] [![Build Status][travis-image]][travis-url] [![Downloads][npm-downloads]][npm-url] [![Code Climate][codeclimate-quality]][codeclimate-url] [![Coverage Status][codeclimate-coverage]][codeclimate-url] [![Dependencies][david-image]][david-url] ## Install - Download [the latest package][download] - NPM: `npm install mithril-router` ## Usage **Node.js / Browserify** ```js // Include mithril var m = require('mithril') // Pass mithril to the router. // Only required to overload once, subsequent overloads will // return the same instance require('mithril-router')(m) ``` **Browser** ```html ``` ## 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 route - `m.route(element:DOMElement)`: bind elements while abstracting away route mode - `m.route(namespace|route(, parameters:Object))`: programmatic redirect w/ arguments - `m.route(namespace|route(, replaceHistory:Boolean))`: programmatic redirect w/ replacing history entry - `m.route(namespace|route(, parameters:Object, replaceHistory:Boolean))`: programmatic redirect w/ arguments and replacing history entry - `m.route(rootElement:DOMElement, routes:Object)`: configure app routing - `m.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** ```js m.route(document.body, { "/": { controller: home, namespace: "index", root: true }, "/login": { controller: login, namespace: "login" }, "/dashboard": { controller: dashboard, namespace: "dashboard" } }) ``` **Classic** ```js m.route(document.body, "/", { "/": { controller: home, namespace: "index" }, "/login": { controller: login, namespace: "login" }, "/dashboard": { controller: dashboard, namespace: "dashboard" } }) ``` --- ### m.route.mode See [Mithril.route.html#mode][mithril-mode] --- ### m.route.param() See [Mithril.route.html#param][mithril-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, when `true` 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 ```js // user => /user/ m.reverse('user') // user => /user/:id => /user/23 m.reverse('user', { params: { id: 23 }}) // user => /user/:id => /user/23?include=profile m.reverse('user', { params: { id: 23 }, query: { include: 'profile' }}) // user => /user/:id => #/user/23?include=profile m.route.mode = 'hash' m.reverse('user', { prefix: true, params: { id: 23 }, query: { include: 'profile' }}) // user => /user/:id => /api/user/23?include=profile m.reverse('user', { prefix: '/api', params: { id: 23 }, query: { include: 'profile' }}) ``` ## License Licensed under [The MIT License](https://github.com/nijikokun/mithril-router/blob/master/LICENSE). [license-url]: https://github.com/nijikokun/mithril-router/blob/master/LICENSE [travis-url]: https://travis-ci.org/nijikokun/mithril-router [travis-image]: https://img.shields.io/travis/nijikokun/mithril-router.svg?style=flat [npm-url]: https://www.npmjs.com/package/mithril-router [npm-license]: https://img.shields.io/npm/l/mithril-router.svg?style=flat [npm-version]: https://img.shields.io/npm/v/mithril-router.svg?style=flat [npm-downloads]: https://img.shields.io/npm/dm/mithril-router.svg?style=flat [coveralls-url]: https://coveralls.io/r/Nijikokun/mithril-router [coveralls-coverage]: https://img.shields.io/coveralls/jekyll/jekyll.svg [codeclimate-url]: https://codeclimate.com/github/nijikokun/mithril-router [codeclimate-quality]: https://img.shields.io/codeclimate/github/Nijikokun/mithril-router.svg?style=flat [codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/Nijikokun/mithril-router.svg?style=flat [david-url]: https://david-dm.org/nijikokun/mithril-router [david-image]: https://img.shields.io/david/nijikokun/mithril-router.svg?style=flat [download]: https://github.com/nijikokun/mithril-router/archive/v1.2.3.zip [mithril]: https://github.com/lhorie/mithril.js [mithril-mode]: http://lhorie.github.io/mithril/mithril.route.html#mode [mithril-param]: http://lhorie.github.io/mithril/mithril.route.html#param

近期下载者

相关文件


收藏者