https://github.com/bpierre/miniroutes
Mini routing system based on regular expressions
https://github.com/bpierre/miniroutes
routing
Last synced: 7 days ago
JSON representation
Mini routing system based on regular expressions
- Host: GitHub
- URL: https://github.com/bpierre/miniroutes
- Owner: bpierre
- License: mit
- Created: 2014-03-05T16:45:58.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-02-13T17:18:01.000Z (over 6 years ago)
- Last Synced: 2025-06-05T21:12:12.159Z (16 days ago)
- Topics: routing
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# miniroutes [](https://travis-ci.org/bpierre/miniroutes)
Mini routing system based on regular expressions.
## Usage
```js
var miniroutes = require('miniroutes');var paths = [
// Match 'foo' and 'foo/'
[ 'foo', /^foo\/?$/ ],// Match 'bar', 'bar/', 'bar//'
[ 'bar', /^bar(?:\/([^\/]+))?(?:\/([^\/]+))?\/?$/ ]];
var routing = miniroutes(paths, function(route, previous) {
// `route` is the matched route
// `previous` is the previously matched route
console.log(route);
});routing('foo');
// Console output: { name: 'foo',
// params: [],
// path: 'foo' }routing('bar/param1');
// Console output: { name: 'bar',
// params: ['param1', null],
// path: 'bar/param1' }routing('bar/param1/param2');
// Console output: { name: 'bar',
// params: ['param1', 'param2'],
// path: 'bar/param1/param2' }
```You can also combine miniroutes with [minihash](https://github.com/bpierre/minihash):
```js
var miniroutes = require('miniroutes');
var minihash = require('minihash');var routes = [ /* … */ ];
var hash = minihash('!/', miniroutes(routes, function(route, previous) {
console.log(route, previous);
}));
```## Installation
```
$ npm install miniroutes
```## Browser compatibility
IE9+ and modern browsers.
[](https://ci.testling.com/bpierre/miniroutes)
## License
[MIT](LICENSE)
## Special thanks
Illustration made by [Raphaël Bastide](http://raphaelbastide.com/) with [scri.ch](http://scri.ch/).