title: Redirecting with nested routes in koa with koa-router
body: <p>How do I do redirects with nested routes using <code>koa-router</code>?</p>
  
  <p>app.js:</p>
  
  <pre><code>var router = require('koa-router')();
  var route1 = require('./routes/route1');
  var route2 = require('./routes/route2');
  
  router.use('/route1', route1);
  router.use('/route2', route2);
  
  app.use(router.routes());
  </code></pre>
  
  <p>route1.js:</p>
  
  <pre><code>var router = require('koa-router')();
  
  router.all('/', function *() {
      router.redirect('/route2');
  });
  
  module.exports = router.routes();
  </code></pre>
  
  <p>route2.js:</p>
  
  <pre><code>var router = require('koa-router')();
  
  router.all('/', function *() {
      this.body = "route2";
  });
  </code></pre>
  
  <p>The above code results in the following error at runtime when navigating to <code>/route1</code>:</p>
  
  <pre><code>TypeError: Cannot read property '0' of undefined
    at Router.redirect (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/koa-router/lib/router.js:477:18)
    at Object.&lt;anonymous&gt; (/Users/colevarner/fullpower/node/motionxlive-koa/routes/support.js:54:12)
    at next (native)
    at onFulfilled (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:65:19)
    at /Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:54:5
    at Object.co (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:50:10)
    at Object.toPromise (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:118:63)
    at next (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:99:29)
    at onFulfilled (/Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:69:7)
    at /Users/colevarner/fullpower/node/motionxlive-koa/node_modules/co/index.js:54:5
  </code></pre>