路由安装依赖cnpminstallkoa-router--save修改index.jsconstkoa=require('koa');constrouter=require('koa-router')();constapp=newkoa();router.get('/',async(ctx,next)=>{ctx.response.body="
hello,world
"})app.use(router.routes());app.listen(3000);console.log(`appstartatlocalhost:3000`);http://localhost:3000/别页面constkoa=require('koa');constrouter=require('koa-router')();constapp=newkoa();router.get('/',async(ctx,next)=>{ctx.response.body="
你好,世界
"})router.get('/hello',async(ctx,next)=>{ctx.response.body="这是你好页面"})router.get('/hello/:name',async(ctx,next)=>{varname=ctx.params.name;ctx.response.body=`
hello,${name}
`})app.use(router.routes());app.listen(3000);console.log(`appstartatlocalhost:3000`);http://localhost:3000/hellohttp://localhost:3000/hello/biaopost