new-koa-router
Router for Koa.js
Installation
Install using npm:
npm install new-koa-router
Contributing
Please submit all issues and pull requests to the new-koa-router repository!
Tests
Run tests using npm test
Support
If you have any problem or suggestion please open an issue here.
Example
Simple
;; ;; router .get"/users/:type/:id",ctx.body = ctx.params .get"/posts",ctx.body = "GET /posts" .post"/users",ctx.body = "POST /users" .post"/posts",ctx.body = "POST /posts"; app.userouter.routes;app.listen3000;
Middleware
; router .get"/users", middleware,ctx.body = ctx.user .get"/users/:type/:id",ctx.body = ctx.params .get"/posts",ctx.body = "GET /posts" .post"/users",ctx.body = "POST /users" .post"/posts",ctx.body = "POST /posts";
Use
;;;;; ;; routerPrivate.usekoaJwt;routerPrivate .get'/jwt',; app.userouterPrivate.routes;app.listen3000;
Redirect
router.redirect'/source', '/destination';
or
router.get"/source",;
Prefix
; router.get"/",;router.post"/:id",;