1.koa-router基本使用
```
const Koa = require('koa')
const Router = require('koa-router')
const app = new Koa()
const router = new Router()
router.get('/users/:id', ctx => {
ctx.body = "这是用户列表" + ctx.params.id
})
app.use(router.routes())
```
2. 路由前缀
```
const usersRouter = new Router({ prefix: '/users'})
usersRouter.get('/:id', ctx => {
ctx.body = "这是用户列表" + ctx.params.id
})
app.use(usersRouter.routes())
```
3.路由中间件
```
const auth = async (ctx, next) => {
if (ctx.url !== '/users') {
ctx.throw(401)
}
await next()
}
usersRouter.get('/:id', auth, ctx => {
ctx.body = "这是用户列表" + ctx.params.id
})
```