Update README

master
Buddy Sandidge 9 years ago
parent cc45cf24ee
commit 1797f41fc5

@ -49,4 +49,28 @@ router.route('/some/path/here', function (err, maybeResults) {
// Error: missing route or any other error that might happen
// maybeResults: The return value from the hander from add
})
// add routes with regex
router.add(['/by/regex', /(\d+)/g], function (one, two, three) {
// one === '1', two === '2', three === '3'
})
router.route('/by/regex/1-2-3')
function toInt(part) {
var results = /^(\d+)$/.exec(part)
return results ? parseInt(results[0], 10) : null
}
// add routes with function
var router = new Router()
router.add(['by', 'func', toInt], function (val) {
// val === 123
})
router.route('/by/func/123')
// Can check for not found route
router.route('/unknown/route', function (err) {
// Router.isNotFound(err) === true
})
```

Loading…
Cancel
Save