Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/narirou/hasher
Tiny hashchange router inspired by express.js & page.js.
https://github.com/narirou/hasher
hashchange router
Last synced: about 5 hours ago
JSON representation
Tiny hashchange router inspired by express.js & page.js.
- Host: GitHub
- URL: https://github.com/narirou/hasher
- Owner: narirou
- Created: 2014-03-15T07:00:18.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-24T17:26:55.000Z (about 8 years ago)
- Last Synced: 2023-08-01T22:15:06.834Z (over 1 year ago)
- Topics: hashchange, router
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
hasher
======> A tiny hashchange router inspired by express.js & page.js
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![MIT Licensed][license-image]][license-url][travis-image]: https://img.shields.io/travis/narirou/hasher.svg?style=flat-square
[travis-url]: https://travis-ci.org/narirou/hasher
[coveralls-image]: https://img.shields.io/coveralls/narirou/hasher.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/narirou/hasher?branch=master
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square
[license-url]: http://opensource.org/licenses/MIThasher is a tiny hashchange router.
Most web applications now use "pushState" for its routing function.
"hashchange" is legacy solution, but it is still useful for the application without server
(for example: local node-webkit applications).Usage
-----```javascript
import hasher from 'hasher';hasher('/', index);
hasher('/user/:id', load, show);
hasher('/user/:id/edit', load, edit);
hasher('/user/:id/delete', del);hasher('*', notfound);
// Begin monitoring hashchange events
hasher();
```API
---#### hasher( route, callback[, callback...] ) / hasher.set(...)
- route {String}
- callback {Function}Set routes and callbacks.
Each callback is invoked `params` object and `next` function.```javascript
function load(params, next) {
params.num; //-> '001'
params.article; //-> 'first-post'
next(); // run `edit` callback
}function edit() {
console.log('it called after `load` function.');
}hasher('/blog/:num/:article/edit', load, edit);
hasher.redirect('/blog/001/first-post/edit');
```#### hasher( route ) / hahser.redirect(...)
- route {String}Redirect hashchange route.
#### hasher() / hasher.start()
Begin monitoring hashchange events.#### hasher.stop()
Stop monitoring hashchange events.#### hasher.reset()
Stop monitoring hashchange events and clear all options.Based on
--------* [page.js](https://github.com/visionmedia/page.js) by TJ Holowaychuk.