API: nuxt.renderRoute(route, context)

  • Type: Function
  • Arguments:
    • String : route to render
    • Optional, Object, context given, available keys: req & res
  • Returns: Promise
    • html: String
    • error: null or Object
    • redirected: false or Object

Render a specific route with a given context.

This method should be used mostly for test purposes as well with nuxt.renderAndGetWindow.

nuxt.renderRoute should be executed after the build process in production mode (dev: false).

Example:

  1. const { Nuxt, Builder } = require('nuxt')
  2. const config = require('./nuxt.config.js')
  3. config.dev = false
  4. const nuxt = new Nuxt(config)
  5. new Builder(nuxt)
  6. .build()
  7. .then(() => nuxt.renderRoute('/'))
  8. .then(({ html, error, redirected }) => {
  9. // `html` will always be a string
  10. // `error` not null when the error layout is displayed, the error format is:
  11. // { statusCode: 500, message: 'My error message' }
  12. // `redirected` is not `false` when `redirect()` has been used in `asyncData()` or `fetch()`
  13. // { path: '/other-path', query: {}, status: 302 }
  14. })