A express-liked router component for koa2
You can follow the instructions below to setup a router componnent in koa@2 environment.
- node version > 8.10
- depends on koa@2.0
- If you use npm to manage your dependencies, run
npm install koa2-router
- Import component
const Router = require('koa2-router');
- Create a router
const router = Router(opts);
- Mount a router to a koa application
const app = new Koa();
app.use(router);
- Mount a router to another router
const router2 = Router();
router2.use(...);
router.use('/users', router2);
- use http method handle request
router2.get('/:userId', ctx => ctx.body = `hello user ${ctx.params.userId}`);
You should clone thie repository down to your file system, and execute
npm run test
This project is licensed under the MIT License
- Thanks to the expressjs/express project
- Thanks to the koa-router project