nuxt.renderRoute(route, context)
- Type:
Function - Arguments:
String: route to render- Optional,
Object, context given, available keys:req&res
- Returns:
Promisehtml:Stringerror:nullorObjectredirected:falseorObject
Render a specific route with a given context.
This method should be used mostly for test purposes as well as with nuxt.renderAndGetWindow.
nuxt.renderRoute should be executed after the build process in production mode.
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()
What's next
Check out the the Components Glossary book
Contributors
Debbie O'Brien
Sébastien Chopin
Benjamin Canac
fgiraud
Sergey Bedritsky
Alba Silvente Fuentes
Alexander Lichter
Krutie Patel
Daniel Roe
pooya parsa
Pim
Ahad Birang
Caught a mistake or want to contribute to the documentation? Edit this page on GitHub!
