Skip to content
Lightweight and flexible URL pattern matching in JavaScript.
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Light and flexible URL routing in JavaScript.


You'll need mocha to run the tests.

Run $ npm install -g mocha. The -g flag tells the NPM to install the dependencies globally so mocha's binaries goes in your /usr/bin directory.

Then run $ mocha.


You'll need uglify-js to minify the script.

Install it with $ npm install -g uglify-js, then run $ make.


Register a new route:'/hello/world', function() {
  console.log('Hello, world');

Then match some path against route table:

var match = way.match('/hello/world');

This will return the first route to match or undefined if none.

The route object has the collection of actions and eventually parsed parameters.

match.actions; //-> [function() { console.log('Hello, world'); }]
match.params;  //-> {}

You can provide multiple actions.'/hello/world', function() {/* 1 */}, function() {/* 2 */});

That way you have control over the flow and do things like if the first action do not return true, it won't call the next one, or pass the returning value from the current action to the next one, or anything else that suits you. I told you it was flexible. :)

WayJS works in both browser and Node.

Pattern syntax:

Named parameters

Capture anything except forward slashes and save in way.params with given name.'/log/:message', function() {

Optional groups

Matches with or without the snippet inside the parenthesis.'(/good)/bye', function() {


Capture everything, including slashes and save in way.params.splat. You can include multiple splats, returning an array.'/goto/*', function() {
  console.log('Goto: ', way.params.splat[0]);

All the special syntaxes above can be combined to create powerful routing patterns.


v0.3.2 2012-09-05

  • Changed to multiple actions instead of allowing multiple matches
  • Accepts multiple splats
  • Tests updated accordingly

v0.2.1 2012-08-24

  • Changed patterns regex to do exact matches

v0.2.0 2012-08-23

  • Accepts multiple matches, returning a collection of them
  • Fixed bug with parameter values being sliced

v0.1.0 2012-08-21

  • First version
Something went wrong with that request. Please try again.