使用指定的上下文对象渲染指定的路由路径。
和 nuxt.renderAndGetWindow 类似,该方法只用于 测试目的。
nuxt.renderRoute 需在生产模式(dev: false)的编译过程之后才可调用。
例如:
const Nuxt = require(nuxt)
const config = require(./nuxt.config.js)
config.dev = false
const nuxt = new Nuxt(config)
nuxt.build()
.then(() => {
return nuxt.renderRoute(/)
})
.then(({ html, error, redirected }) => {
// html 类型为 string
// 当显示 error 视图时,error 的值不为 null。error 对象的格式为:
// { statusCode: 500, message: My error message }
// redirected is not false when redirect() has been used in data() or fetch()
// 如果 `redirect` 方法已在 `asyncData` 或 `fetch` 方法中调用,redirected 的值非 false,其格式如下:
// { path: /other-path, query: {}, status: 302 }
})