Environment: Browser.

The getPage() function allows us to access the pageContext in the browser.

When we use getPage(), we essentially do Server-side Routing.

// *.page.client.js
// Environment: Browser

import { getPage } from 'vite-plugin-ssr/client'


async function hydrate() {
  const pageContext = await getPage()

  // We can now hydrate our page using `pageContext.Page`
  // ...

The pageContext returned by getPage() is a subset of the pageContext defined on the server-side; to determine what pageContext is sent to the browser we use passToClient.

The pageContext is serialized and passed from the server to the browser with json-s.

In production, the pageContext is prefetched and getPage() merely makes it available.

See also