https://github.com/peburrows/router.js
javascript router for single-page apps
https://github.com/peburrows/router.js
Last synced: 12 months ago
JSON representation
javascript router for single-page apps
- Host: GitHub
- URL: https://github.com/peburrows/router.js
- Owner: peburrows
- Created: 2011-05-17T17:13:08.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2012-05-18T20:57:16.000Z (about 14 years ago)
- Last Synced: 2025-06-07T11:08:50.029Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 85 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Usage
```javascript
// create a router
var router = new Router();
// define routes
router.define('/hello/world', function(){
// `this` refers to the request inside of the handler
if(this.method == 'GET'){ alert('hello, world'); }
else { alert('hello, world via ' + this.method); }
}).resources('users', {
show : function(){
$.get(this.path, this.queryParams, function(data) {
$('#wrapper').html(data);
});
},
index : function(){
// load users...
},
edit : function(){
// load the edit user form
}
}).catchAll(function(){
// all requests that do not match route will be passed to this handler
}).default(function(){
// the default route to push on initial page load
});
```
## Requirements
Currently requires [jQuery](https://github.com/jquery/jquery), [jquery.url.js](https://github.com/peburrows/jQuery-URL-Parser), and [jquery.ba-bbq.js](https://github.com/cowboy/jquery-bbq), although I'll soon be working to eliminate those dependencies