0.3.0 • Published 8 years ago

eli-router v0.3.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

eli-router

Commitizen friendly Build Status

Core of a js router, supporting nested route with multiple URL paramters and handlers.

Can be integrated into Nodejs or Browser framework such as koa and react.

(For koa)https://github.com/nameoverflow/eli-router

Used by (eliter)https://github.com/nameoverflow/eliter

USEAGE

let Router = require('eli-router')

let R = new Router()

// :: stands for a URL paramter.
R.route('/admin/::').end(id => `Id: ${id}`)

// URL.pathname = '/admin/1234567'

let matched = R.dispatch(URL.pathname).pop()
Router.handle(matched) // => "Id: 1234567"


R.route('/user/::/').route('/messageto/::').end((user, target) => `User ${user} send message to id ${target}`)

Router.handle(R.dispatch('/user/123/messageto/456').pop()) // => "User 123 send message to id 456"

// work with asterisk 

R.route('/something/*').end(() => 'Something')

let matched = R.dispatch('/something/others/blahblah').pop()
Router.handle(matched) // => "Something"


function checkSession() {
    // Function to check session...

}

function showID(id) {
    // Show id to client....
}

R.route('/user', checkSession).route('/::').end(showID)

R.dispatch('/user/123') // => [[showID, [123]], [checkSession, []]]
0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago