Skip to content
Url-based router for Node.js and browsers.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
build
examples
lib
test
.gitignore
.travis.yml
Makefile
README.md
package.json
rou.min.js

README.md

Rou Build Status

Url-based router for Node.js and browsers.

Getting Started

In the Node.js

You can install using Node Package Manager (npm):

npm install rou

In the Browsers

<script type="text/javascript" src="rou.min.js"></script>

Also RequireJS module format supported.

API

var router = Rou();

router
    .when('/objects/{oid}/slaves/{sid}')
        .method('get') // method should be 'get'
        .param('new', true) // param 'new' should be
        .param('category', false) // param 'category' shouldn't be
        .param('bounds') // param 'bounds' should be non-empty
        .param('geometry', 'polyline') // param 'bounds' should be 'polyline'
        .param('type', ['road', 'railway']) // param 'type' should be 'road' or 'railway'
        .param('oid', /^\d+$/) // param 'oid' should be integer
        .then(function(req) { // controller action
            // req.query.oid, req.query.sid now available
            // controller action
        })
    .when('/objects/new')
        .then('/objects', { new : 1 }) // rewrite /objects/new to /objects/?new=1
    .when('/objects/{type}')
        .param('type', ['road', 'railway'])
        .then('/objects') // rewrite /objects/road or /objects/railway to /objects/?type=road or /objects/?type=railway
    .otherwise(function() {
        show404();
    });

router.route({
    method : 'get',
    path   : '/objects/road',    
    query  : { new : '1' }    
});
Something went wrong with that request. Please try again.