Koa:koa-route和koa-mount之间有什么区别。 我应该什么时候使用每个?

我正在尝试使用Koa.js,并检出以下路由请求模块:1. koa-route 2. koa-mount

当我在谷歌检查他们的github页面/教程时,这些例子看起来几乎相似,只是细微的差别。

  1. 对于koa路线:

    var route = require('koa-route'); app.use(route.get('/', index)); //functions to handle the request function* index(){ this.body = "this should be home page!"; } 
  2. 对于科阿芒:

      //syntax to add the route var mount = require('koa-mount'); var a = koa(); app.use(mount('/hello', a)); //functions to handle the request a.use(function *(next){ yield next; this.body = 'Hello'; }); 

唯一的区别似乎是mount需要一个中间件来处理请求,而route需要一个生成器来处理请求。

我很困惑什么时候使用什么和什么时候使用(在一些教程中看到)?

Koa-mount的目的是将一个应用程序安装到另一个应用程序中。 例如,您可以创build独立的博客应用程序,并将其挂载到其他应用程序。 你可以挂载别人创build的应用程序。