Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kristoferjoseph/thataway

Minimal URL routing library
https://github.com/kristoferjoseph/thataway

minimal router vanilla-js

Last synced: 5 days ago
JSON representation

Minimal URL routing library

Awesome Lists containing this project

README

        

# πŸ‘‰β˜οΈ Thataway πŸ‘‡πŸ‘ˆ
Minimal url routing library.

- Written in plain ol JavaScript so **no transpile needed**πŸ”₯
- ~8k minifiedπŸ’₯
- Simple api:
- register
- subscribe
- unsubscribe
- navigate

## Install
`npm i thataway --save`

## Usage
Simplest working example

```
var createRouter = require('thataway')
var router = createRouter()
router.register('/things', {animal:'raccoon'})
router.subscribe(update)

function update(data) {
console.log(data)// Outputs {animal:'racoon',path:'/things',params:{},query:{}}
}

router.navigate('/things')
router.unsubscribe(update)
```

Complex urls
```
var createRouter = require('thataway')
var router = createRouter()

router.register('/things/:comment/:id', {animal:'raccoon'})
router.subscribe(update)

function update(data) {
console.log(data)// Outputs {animal:'racoon',path:'/things', params: { comment:'123', id:'456' }, query: { can: do }, hash: { stuff: too }}
}

router.navigate('/things/123/456?can=do#stuff=too')
router.unsubscribe(update)
```

## Test
`npm it`