Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pfrazee/phoenix-router
a simple SPA router
https://github.com/pfrazee/phoenix-router
Last synced: 14 days ago
JSON representation
a simple SPA router
- Host: GitHub
- URL: https://github.com/pfrazee/phoenix-router
- Owner: pfrazee
- Created: 2015-01-06T19:37:58.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-06T19:38:11.000Z (almost 10 years ago)
- Last Synced: 2024-10-30T15:54:37.243Z (2 months ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Phoenix Router
A simple SPA router
```js
var router = require('phoenix-router')// usage: router(hash, default-page)
router('#/', 'home')
// => ['home']router('#/home', 'home')
// => ['home']router('#/msgs', 'home')
// => ['msgs']router('#/msgs/5', 'home')
// => ['msgs', '5']router('#/msgs/5/author', 'home')
// => ['msgs', '5/author']router('#/msgs/5/author?foo=bar&hello=world', 'home')
// => ['msgs', '5/author', { foo: 'bar', hello: 'world' }]router('#/other?foo=bar&hello=world', 'home')
// => ['other', null, { foo: 'bar', hello: 'world' }]router('badinput', 'home')
// => ['notfound']// here's how you use it:
var pages = {
home: console.log.bind(console, 'home page'),
msgs: console.log.bind(console, 'message page'),
notfound: console.log.bind(console, '404')
}
var route = router(window.location.hash, 'home')
var page = pages[route[0]] || pages.notfound
page(route)
```