Static GitHub Issues

[426] Got "Cannot read property 'url' of undefined" error when using .renderRoute

prev: $nuxt.$on('routeChanged') stops firing
next: Generate valid html

Hi, I went into trouble when using renderRoute. The following is what I did:

Env

Mac OS X EI Capitan 10.11.6 Node v7.7.4

5 Simple Steps

  1. Download nuxt-koa template
$ vue init nuxt/koa (choose koa v2)
  1. Install dependencies
$ yarn
  1. Try to run before changing anything, and it works fine
$ npm run dev  # which works fine
  1. Change app.js to use renderRoute
// app.js

// ...

// Change the middleware to use renderRoute
app.use(async (ctx, next) => {
  ctx.status = 200 // koa defaults to 404 when it sees that status is unset
  // await nuxt.render(ctx.req, ctx.res)
  const result = await nuxt.renderRoute('/')
  console.log(result.error)
})
  1. Run again
$ npm run dev # error is printed

Error Message:

{ statusCode: 500,
  message: 'Cannot read property \'url\' of undefined' }

Am I using renderRoute in a wrong way? Any idea? Thanks!

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c370">#c370</a>)</em></sub></div>