-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# WayJS | ||
|
||
Light and flexible URL routing in JavaScript. | ||
|
||
## Tests: | ||
|
||
You'll need [mocha](https://github.com/visionmedia/mocha) to run the tests. | ||
|
||
Run `npm install -g`. The `-g` flag tells the NPM to install it globally so mocha's binaries goes in `/usr/bin` directory. | ||
|
||
Then run `mocha`. | ||
|
||
## Usage: | ||
|
||
Register a new route: | ||
|
||
way.map('/hello', function() { | ||
console.log('Hello, world'); | ||
}); | ||
|
||
Then match some path against route table: | ||
|
||
var action = way.match('/hello'); | ||
|
||
This will return either the callback or null if no matching route is found. | ||
|
||
action(); //-> console.log('Hello, world'); | ||
|
||
Way can be used within the browser or with Node. | ||
|
||
Route patterns accepts 3 special syntaxes: | ||
|
||
### Named parameters | ||
|
||
way.map('/log/:message', function() { | ||
console.log(way.params.message); | ||
}); | ||
|
||
### Optional groups | ||
|
||
way.map('(/good)/bye', function() { | ||
console.log('Farewell!!'); | ||
}) | ||
|
||
### Splats | ||
|
||
way.map('/goto/*', function() { | ||
console.log('Goto: ', way.params.splat); | ||
}); | ||
|
||
They can be combined to create powerful routes. | ||
|
||
Also please note that routes are matched in the order they're registered. | ||
|
||
## Roadmap: | ||
|
||
1. Hooks | ||
2. Better tests | ||
3. Skipping routes |