Want to take a look at our new docs? Our new docs are now in beta. Have fun!

nuxt.renderRoute(route, context)

  • Type: Function
  • Arguments:
    1. String : route to render
    2. 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.

Example:

const { loadNuxt, build } = require('nuxt')

async function start() {
  // Get nuxt instance for start (production mode)
  // Make sure to have run `nuxt build` before running this script
  const nuxt = await loadNuxt({ for: 'start' })

  const { html, error, redirected } = await nuxt.renderRoute('/')

  // `html` will always be a string

  // `error` not null when the error layout is displayed, the error format is:
  // { statusCode: 500, message: 'My error message' }

  // `redirected` is not `false` when `redirect()` has been used in `asyncData()` or `fetch()`
  // { path: '/other-path', query: {}, status: 302 }
}

start()

Contributors

Contribution for this page is now closed. If you would like to contribute please check out our new docs are now in beta. Have fun!

Platinum Sponsors

StoryblokMoovweb Support Us