onAfterRenderHtml() hook

Environment: server.
Implemented by: vike-vue.

You need vike-vue to be able to use onAfterRenderHtml().

Hook called at the end of rendering the page on the server-side. It's usually used for integrating tools, such as state management tools.

It's called upon rendering the first page.

  • It's called regardless of whether SSR is disabled. (The first page the user visits is always rendered to HTML: when SSR is disabled then the HTML is just an HTML shell that doesn't contain the content of the page.)
  • It isn't called upon page navigation. (Pages aren't rendered to HTML upon page navigation.)

If you want to perform an action only upon SSR then check whether pageContext.Page is set:

// +onAfterRenderHtml.js
 
export function onAfterRenderHtml(pageContext) {
  const isSSR = !!pageContext.Page
  if (isSSR) {
    // ...
  }
}

See also