您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

API nuxt.renderRoute

API: nuxt.renderRoute(route, context)

nuxt.renderRoute(route, context = {})

类型: Function

参数:

String,带渲染的路由路径

可选, Object, 指定的上下文对象,可用的键: req 和 res

返回: Promise

html: String

error: null 或 Object

redirected: false 或 Object

使用指定的上下文对象渲染指定的路由路径。

和 nuxt.renderAndGetWindow 类似,该只用于 测试目的。

nuxt.renderRoute 需在生产模式(dev: false)的编译过程之后才可。

例如:

const Nuxt = require('nuxt')
const con = require('./nuxt.con.js')
con.dev = false
const nuxt = new Nuxt(con)

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 }
  })

联系我
置顶