koa 路由问题
发布于 9 年前 作者 demohi 4894 次浏览 最后一次编辑是 8 年前 来自 问答
var mount = require('koa-mount');
module.exports = function(app){
  return function * routes(next){
      function *ab (next){
          this.body = 'hello Hello';
          yield next;
      }
      app.use(mount('/hello',ab));
      yield next;
  }
};
app.use(routes(app));

请教一下 这样写路由,为什么不生效呢。

2 回复
var mount = require('koa-mount');

module.exports = function(app){
      function *ab (next) {
          this.body = 'hello Hello';
      }
      app.use(mount('/hello',ab));
};

@JacksonTian 感谢回复 这样是可以,就是没法当成中间件来用了。

回到顶部