|
|
|
@ -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
|
|
|
|
|
})
|
|
|
|
|
```
|
|
|
|
|