Skip to content

nameoverflow/eli-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, []]]

About

Core of a js router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published