New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mithril-router

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mithril-router

Django style router for Mithril.js

latest
npmnpm
Version
1.3.3
Version published
Maintainers
1
Created
Source

Mithril Router

Django style router for Mithril.js

version License Build Status Downloads Code Climate Coverage Status Dependencies

Install

  • Download the latest package
  • NPM: npm install mithril-router

Usage

Node.js / Browserify

// 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

<script src="path/to/mithril.js" type="text/javascript"></script>
<script src="path/to/mithril.router.js" type="text/javascript"></script>

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

m.route(document.body, {
  "/": { controller: home, namespace: "index", root: true },
  "/login": { controller: login, namespace: "login" },
  "/dashboard": { controller: dashboard, namespace: "dashboard" }
})

Classic

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

m.route.param()

See Mithril.route.html#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

// 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.

Keywords

router

FAQs

Package last updated on 22 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts