The router middleware for PXE.js.
Install @pxe/router
.
# NPM
npm i @pxe/router
# Yarn
yarn add @pxe/router
All the router methods, event and declarations.
Router
root?: string
: The root URLConstruct a router. The root is used to run the middlewares if the request URL starts with the root URL.
router.use
...m: Middleware[]
: The middlewareAdd a middleware to the middleware list. You can add multiple middleware within a single call.
route.handle
route: string
: The target route path namehandler: Router.RouteHandler
: The route handlerRegister a handler for a specific path name.
route.param
route: string
: The target route path namehandler: Router.RouteHandler
: The route handlerThe same as route.param
, but instead handles dymanic routes.
route.invoke
ctx: Server.Context
: The server contextnext: Server.NextFunction
: Call the next middleware...args: any[]
: The previous middleware passed argumentsThe callback of the router. This can be used as a middleware:
app.use(router.invoke.bind(router));
// Or shorter
app.use(router);