中间件 koa-router
安装
npm install --save koa-router
使用
const Koa = require('koa'); const Router = require('koa-router'); const app = new Koa(); const router = new Router(); router.get('/', function (ctx, next) { ctx.body="Hello Word"; }); app.use(router.routes())
.use(router.allowedMethods());
app.listen(3000,()=>{ console.log('starting at port 3000'); });