Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nameoverflow/eli-router
Core of a js router
https://github.com/nameoverflow/eli-router
Last synced: 29 days ago
JSON representation
Core of a js router
- Host: GitHub
- URL: https://github.com/nameoverflow/eli-router
- Owner: nameoverflow
- Created: 2016-02-18T08:01:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-24T05:30:27.000Z (almost 9 years ago)
- Last Synced: 2024-10-16T15:31:01.200Z (3 months ago)
- Language: JavaScript
- Size: 14.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eli-router
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Build Status](https://travis-ci.org/nameoverflow/eli-router.svg?branch=master)](https://travis-ci.org/nameoverflow/eli-router)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
``` js
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, []]]
```