Route Hashing Method

Update getStaticProps

User Context is restored within getStaticProps through the following steps:

  1. The User Context stored in the hashed slug is immediately parsed at the top of the getStaticProps function. The original path’s slug is restored in case it is needed elsewhere in the app.

  2. The Intelligems config is pulled from our CDN.

  3. The User Context, the Intelligems config, and all other page props are merged and returned as props.

Example Configuration

import { IgRouteContext, withIntelligemsProps } from '@intelligems/headless/next'

export async function getStaticProps({
  params,
  locale,
  locales,
  preview,
}: GetStaticPropsContext<{ slug: string }>) {
  const igContext = IgRouteContext.getUserContext(params)

  const categories = ...
  const pages = ...

  ...
  ...
  
  const finalProps = await withIntelligemsProps(
      {
        categories,
        pages,
        product,
        relatedProducts,
      },
      igContext
    )
  
  return {
    props: finalProps,
    revalidate: 200,
  }
}

export async function getStaticPaths({ locales }: GetStaticPathsContext) {
  const { products } = ...

  return {
    paths = products.map((product: any) => `/product${product.path}`),
    fallback: 'blocking',
  }
}