Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/kristoferjoseph/thataway
- Owner: kristoferjoseph
- License: apache-2.0
- Created: 2016-07-31T20:29:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-20T18:17:18.000Z (over 6 years ago)
- Last Synced: 2024-10-13T10:53:14.487Z (about 1 month ago)
- Topics: minimal, router, vanilla-js
- Language: JavaScript
- Homepage:
- Size: 164 KB
- Stars: 15
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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`