title: How can I configure koa-router to run common code before any of a certain group of routes?
body: <p>I'd like to add some functionality to <code>/module</code> that gets executed for any matching route under that directory.</p>
  
  <p>So for a given set of routes:</p>
  
  <pre><code>/module/
  /module/page
  /module/things
  /module/things/:thingid
  </code></pre>
  
  <p>I want code in a router for <code>/module</code> to run for all of the above routes. <code>/module</code> doesn't render, it just fetches some common data and configures the view context. Then one of the other routes runs and renders the page.</p>
  
  <p>Is this possible with koa-router? Or is there a better package?</p>
  
  <p>Edit:
  I think maybe I have to do a nested router and add middleware prior to the nesting like so:</p>
  
  <pre><code>var subRouter = new Router();
  subRouter.get('/', function *(next){ doSomething(); });
  subRouter.get('/page', function *(next){ doSomething(); });
  subRouter.get('/things', function *(next){ doSomething(); });
  subRouter.get('/things/thingid', function *(next){ doSomething(); });
  
  mainRouter.use('/module',
                 function *(next) { doPreRouteSteps(); yield next; },
                 subRouter.routes()
  );
  </code></pre>
  
  <p>Seems to be working, but I'm not sure if this is an ugly hack or what. If there is a better way, please advise.</p>