nuxt.renderRoute(route, context)
Render a specific route with a given context.
-
Type:
Function -
Arguments:
-
String: route to render -
Optional,
Object, context given, available keys:req&res
-
-
Returns:
Promise-
html:String -
error:nullorObject -
redirected:falseorObject
-
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()
Edit this page on GitHub
Updated at Tue, Apr 5, 2022
Nazaré da Piedade
Mosaab Emam
Sylvain Marroufin
Iljs Путлер Капут
Daniel Roe
Heitor Ramon Ribeiro
Nero
Sébastien Chopin
Clément Ollivier
Yoon Han
Ikko Ashimine
FamCodings
Ayouli
F. Hinkelmann
felipesuri
Christophe Carvalho Vilas-Boas
Leoš Literák
Trizotti
Marcello Bachechi
Rodolphe
Thomas Underwood
Shek Evgeniy
Lukasz Formela
Hugo Torzuoli
Kareem Dabbeet
tramplay
verebelyicsaba
Adam
Nate Butler
Sandra Rodgers
Arpit Patidar
Matthew Kuehn
Steven DUBOIS
Travis Lindsey
syagawa
Maxime
かる
Al Power
Florent Delerue
quanghm
José Manuel Casani Guerra
Unai Mengual
kazuya kawaguchi
Michael Lynch
Tomachi
pooya parsa
Meir Roth