Constructor
new Router(routeFn, routeHandlersopt)
Constructs a router with a routing function and optionally some preinstalled middlewares.
Note that you can always install more middlewares on the router by calling Router#on.
Name | Type | Attributes | Description |
---|---|---|---|
routeFn | function | A routing function that decides which middleware to run | |
routeHandlers | Map.<Middleware> | <optional> | Map object with middlewares |
Methods
on(route, …fns) → {Router}
Registers new middleware for a given route. The initially supplied routing function may return this route as a string to select the respective middleware for execution for an incoming update.
Name | Type | Attributes | Description |
---|---|---|---|
route | string | The route for which to register the middleware | |
fns | Middleware | <repeatable> | Middleware(s) to register |
- Type:
- Router
otherwise(…fns)
Allows to register middleware that is executed when no route matches, or when the routing function returns undefined
. If this method is not called, then the router will simply pass through all requests to the downstream middleware.
Name | Type | Attributes | Description |
---|---|---|---|
fns | Middleware | <repeatable> | Middleware(s) to run if no route matches |