注意:必须导出
文档地址:https://npm.taobao.org/package/koa-router
例:
const router = require('koa-router')() router.prefix('/users') //设置前缀 router.get('/', async (ctx, next) => { // global.console.log('index'); await ctx.render('index', { title: 'Hello Koa 2!' }) }) router.get('/string', async (ctx, next) => { ctx.body = { title:'koa2 string' } }) router.get('/json', async (ctx, next) => { ctx.body = { title: 'koa2 json' } }) module.exports = router