const Koa = require('koa');
const Router = require('koa-router');
const server = new Koa();
server.listen(8080);
//子路由1
let router1 = new Router();
router1.get('/1', async ctx=>{
ctx.body = 'hello world!'
});
router1.get('/2', async ctx => {
ctx.body = 'hello vue!'
});
//子路由2
let router2 = new Router();
router2.get('/aaa', async ctx=>{
ctx.body = 'aaa';
});
router2.get('/bbb', async ctx => {
ctx.body = 'bbb';
});
//主路由
let mainRouter = new Router();
mainRouter.use(router1.routes());
mainRouter.use(router2.routes());
server.use(mainRouter.routes());
koa路由中间件——koa-router
最新推荐文章于 2024-05-16 10:08:50 发布