Arguments

  1. pathname
    string
    required

    The path of the page.

  2. options
    object
    required

    Options for site version and locale.

Return type

snapshot
Snapshot

An opaque Snapshot object that is only intended to be rendered by the <Page> component.

Examples

Basic usage

The following example sets up a catch all route where page snapshots are fetched from Makeswift and rendered using the <Page> component.

Localization

The following example uses the locale param in getStaticProps to fetch a localized snapshot of a page.

pages/[[...path]].tsx
import { Makeswift, Page as MakeswiftPage } from "@makeswift/runtime/next"

import { client } from "@/makeswift/client"

export async function getStaticPaths() {
  const pages = await client.getPages()

  return {
    paths: pages.map((page) => ({
      params: {
        path: page.path.split("/").filter((segment) => segment !== ""),
      },
    })),
    fallback: "blocking",
  }
}

export async function getStaticProps({ params, previewData, locale }) {
  if (params == null) return { notFound: true }

  const path = "/" + (params.path ?? []).join("/")
  const snapshot = await client.getPageSnapshot(path, {
    siteVersion: Makeswift.getSiteVersion(previewData),
    locale,
  })

  if (snapshot == null) return { notFound: true }

  return { props: { snapshot } }
}

export default function Page({ snapshot }) {
  return <MakeswiftPage snapshot={snapshot} />
}