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.

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

Then run $ mocha.


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 a collection of matches or undefined if no match is found.

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

Each match object has an action function and a params object.

So let's say, after the snippet above you write:'/hello/:name', function(params) {
  console.log('Hello, mister ' +;

Then, match the same path again:

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

Now we got:

matches[0].action(); //-> console.log('Hello, world')
matches[0].params;   //-> {}


matches[1].action(); //-> console.log('Hello, mister world')
matches[1].params;   //-> { name: 'world' }

This way you have control over the flow. Let's you need to "filter" some route, you just register it twice, but in the first you can return a special value that you'll check for before execution the second match. I told you it was flexible! ;)

WayJS works with both browser and Node.

Pattern syntax:

Named parameters

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

Optional groups

Allow flexible routes.'(/good)/bye', function() {


Capture everything, including slashes and save in way.params.splat. No more than 1 splat per route.'/goto/*', function() {
  console.log('Goto: ', way.params.splat);

All the special syntax can be combined to create powerful routes.

Something went wrong with that request. Please try again.