Update README
This commit is contained in:
parent
cc45cf24ee
commit
1797f41fc5
24
README.md
24
README.md
@ -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…
Reference in New Issue
Block a user