https://github.com/jongacnik/routebeer
A little router for the browser for ajaxified sites.
https://github.com/jongacnik/routebeer
Last synced: 11 months ago
JSON representation
A little router for the browser for ajaxified sites.
- Host: GitHub
- URL: https://github.com/jongacnik/routebeer
- Owner: jongacnik
- Created: 2014-09-18T06:06:22.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-12T05:41:44.000Z (over 10 years ago)
- Last Synced: 2025-07-11T03:49:11.289Z (11 months ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# routebeer
A simple router for the browser best enjoyed with [pjax](https://github.com/thybag/PJAX-Standalone)
**Some API Changes in version 0.1.8**
## Usage
var routebeer = require('routebeer')
var router = routebeer({
always : function (data) { // run on every navigate
console.log(data)
},
notFound : function (data) { // run on route not found
console.log(data)
},
root : '/', // define optional base
event : 'pjax:success' // run route check on event
})
.add({ // add a route
name : 'project',
path : '/projects/:project',
load : function (r) { // run when navigating to route
console.log(r) // r will contain route data, such as params
},
unload : function (r) { // run when navigating away from route
console.log(r)
}
})
.add({
name : 'about',
path : '/about',
load : function (r) {
console.log(r)
},
unload : function (r) {
console.log(r)
}
})
.add({
name : 'home',
path : '/',
load : function (r) {
console.log(r)
},
unload : function (r) {
console.log(r)
}
})
.navigate() // init
Path definition using [path match](https://www.npmjs.org/package/path-match)
### Remove
router.remove('home') // removes route
### Events
router
.on('load', function (r) {
})
.on('unload', function (r) {
})
## Bundled Version
If you don't want to mess with a build process you can also include the pre-bundled version found in routebeer.bundled.js in your project which exposes routebeer() globally.