3.路由

2018-11-21  本文已影响0人  阿水日记

1,路由前缀
router.prefix('/users')

这样就可以方便的模块化的管理路由了

2,路由请求及返回格式

//返回模板
router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 2!'
  })
})
//返回字符串
router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
})
////返回json
router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})
上一篇 下一篇

猜你喜欢

热点阅读