1-2 koa-router
作者:互联网
安装koa-router
npm i @koa/router
引用并实例化koad-router
const Koa=require('koa')
const Router=require('@koa/router')
const app= new Koa()
const router = new Router()
router.get('/',ctx=>{ctx.body='Hello World!'})
router.get('/api',ctx=>{ctx.body='Hello Api!'})
app.use(router.routes()).use(router.allowedMethods())
app.listen(3000)
启动
node index.js
标签:body,const,koa,app,ctx,router 来源: https://www.cnblogs.com/mengxiangzhi/p/16241440.html