Router ⇐ ReducerWrapper
Kind: global class
Extends: ReducerWrapper
- Router ⇐
ReducerWrapper- new Router()
- instance
- static
- .CONTINUE
- .BREAK
- .END
- .exit(action, [data]) ⇒
Array
new Router()
Cascading router
router.use([action], [matcher], ...reducers) ⇒ Object
Appends middleware, action handler or another router
Kind: instance method of Router
| Param | Type | Description | ||
|---|---|---|---|---|
| [action] | string |
name of the action | ||
| [matcher] | RegExp \ |
string \ |
function |
The function can be async |
| ...reducers | function \ |
Router |
Example
// middleware
router.use((req, res, postBack) => Router.CONTINUE);
// route with matching regexp
router.use(/help/, (req, res) => {
res.text('Hello!');
});
// route with matching function (the function is considered as matcher
// in case of the function accepts zero or one argument)
router.use('action', req => req.text() === 'a', (req, res) => {
res.text('Hello!');
});
// use multiple reducers
router.use('/path', reducer1, reducer2)
.onExit('exitAction', (data, req, res, postBack) => {
postBack('anotherAction', { someData: true })
});
// append router with exit action
router.use('/path', subRouter)
.onExit('exitAction', (data, req, res, postBack) => {
postBack('anotherAction', { someData: true })
});
Router.CONTINUE
Return Router.CONTINUE when action matches your route
Its same as returning true
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.BREAK
Return Router.BREAK when action does not match your route
Its same as returning false
Kind: static property of Router
Properties
| Type |
|---|
boolean |
Router.END
Returning Router.END constant stops dispatching request
Its same as returning undefined
Kind: static property of Router
Properties
| Type |
|---|
null |
Router.exit(action, [data]) ⇒ Array
Create the exit point
Its same as returning ['action', { data }]
Kind: static method of Router
| Param | Type | Description |
|---|---|---|
| action | string |
the exit action |
| [data] | Object |
the data |
Example
router.use((req, res) => {
return Router.exit('exitName');
});