Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rla/router
Simplest hashchange regex router.
https://github.com/rla/router
frontend routing routing-engine
Last synced: 13 days ago
JSON representation
Simplest hashchange regex router.
- Host: GitHub
- URL: https://github.com/rla/router
- Owner: rla
- License: mit
- Created: 2013-05-16T11:31:49.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-08T12:01:46.000Z (almost 10 years ago)
- Last Synced: 2024-04-11T20:56:27.641Z (10 months ago)
- Topics: frontend, routing, routing-engine
- Language: JavaScript
- Size: 148 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hash-regex-router
Client-side hashchange regex router for [singe-page applications](http://en.wikipedia.org/wiki/Single-page_application).
Works on Chrome 5, Firefox 3.6 and IE 10+.Routes are processed in the order they are added.
## Examples/API
Basic usage:
```javascript
route(/^about/, function() {
console.log('Showing the About page');
});
```With capture groups:
```javascript
route(/^profile\/([0-9]+)/, function(uid) {
console.log('Showing the profile page for user ' + uid);
});```
Default route:
```javascript
route(/.*/, function() {
route.go('home');
});
```Programmatically go to a route (#home):
```javascript
route.go('home');
```Goes to #profile/123:
```javascript
route.go('profile', 123);
```Refresh the current route:
```javascript
route.refresh();
```Disable routing:
```javascript
route.disable();
```Re-enable routing:
```javascript
route.enable();
```Prevent leaving current route:
```javascript
route.leave = function() {
return confirm('Leave the current route?');
};
```## AMD/CommonJS
The source `router.js` uses CommonJS module format. `dist/router-standalone.js`
contains minified build in UMD format that supports both AMD and CommonJS environments and also
sets global `route` when directly in browser.Installing from NPM:
npm install hash-regex-router
If installed through NPM then the module can be directly used in browserify by simply require()'ing
it:```javascript
var route = require('router');
```## Building/testing
Install build dependencies:
npm install
Run static server:
make serve-test
Run tests:
make test
## License
The MIT license.