Route matcher devised for shared rendering JavaScript applications
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Latest commit fb6d4a4 Sep 12, 2016
Permalink
Failed to load latest commit information.
test fix * bug Jan 6, 2015
.editorconfig initial commit Jan 5, 2015
.gitignore initial commit Jan 5, 2015
CHANGELOG.md rt null Jan 6, 2015
LICENSE initial commit Jan 5, 2015
README.md updated documentation and api Jan 5, 2015
index.js Change deprecated unescape() to decodeURIComponent() Sep 12, 2016
package.json 2.0.1 Sep 12, 2016
pathToRegExp.js fix * bug Jan 6, 2015

README.md

ruta3

Route matcher devised for shared rendering JavaScript applications

Install

npm install --save ruta3

Sample Usage

Get a router instance

var ruta3 = require('ruta3');
var router = ruta3();

Add some routes

router.addRoute('/articles', getArticles);
router.addRoute('/articles/:slug', getArticleBySlug);
router.addRoute('/articles/search/*', searchForArticles);

Find a match

router.match('/articles');

You'll get null back if no route matches the provided URL. Otherwise, the route match will provide all the useful information you need inside an object.

Key Description
action The action passed to addRoute as a second argument. Using a function is recommended
next Fall through to the next route, or null if no other routes match
route The route passed to addRoute as the first argument
params An object containing the values for named parameters in the route
splats An object filled with the values for wildcard parameters

License

MIT

(originally derived from routes, which is no longer maintained)