This guide covers the basics of navigating between pages in React Storefront.


React Storefront provides a Link component built on top of next/link that provides additional functionality. As with Next's Link component, you need to specify both as and href props for dynamic routes:

<Link as="/p/1" href="/p/[productId]">
  Red Shirt


You can prefetch and cache the data for a linked page using <Link prefetch="visible|always">. The prefetch accepts two values:

  • "always" - Prefetch the data for the target page as soon as the link is rendered
  • "visible" - Wait until the link is visible in the viewport before prefetching the data for the target page
<Link as="/p/1" href="/p/[productId]" prefetch="visible">
  Red Shirt

By convention, the Link component will compute the URL to prefetch by adding /api/ to the beginning of the href prop. You can override this functionality by providing a prefetchURL prop:

<Link prefetch="visible" as="/p/1" href="/p/[productId]" prefetchURL="">
  Product 1

It is important to note that prefetching can result in significantly more traffic being sent to your API unless you're running behind and edge-based cache that supports shielding and request coalescing like Layer0.

Passing props to the next page

Often times much of the data to be displayed above the fold on a given page is available when the link to that page is created. Common examples are the product name, rating, and price on a PLP. You can pass these to the PDP so they can be displayed in the skeleton while the rest of product data is being fetched from the back end.

Use Link's pageData prop to pass data from the current page to the next page.

<Link as="/p/1" href="/p/[productId]" pageData={{ product: { name: 'Red Shirt' } }}>
  Red Shirt

Here is a complete example with PLP and PDP:

PLP Example

import useSearchResultsStore from 'react-storefront/plp/useSearchResultsStore'
import Link from 'react-storefront/link/Link'
import Rating from 'react-storefront/Rating'
import { createLazyProps, fetchFromAPI } from 'react-storefront/props'

export default function Subcategory(lazyProps) {
  const [state, updateState] = useSearchResultsStore(lazyProps)
  const { loading, pageData } = state

  return (
      {!loading &&, i) => (
          <div key={i}>
              pageData={{ product }} // this data will be immediately available on the PDP while the rest of the data is fetched from the back end
            <Rating value={product.rating} />

Subcategory.getInitialProps = createLazyProps(fetchFromAPI)

PDP Example

import useLazyState from 'react-storefront/hooks/useLazyState'
import { createLazyProps, fetchFromAPI } from 'react-storefront/props'

export default function Product(lazyProps) {
  const [state, updateState] = useLazyState(lazyProps, { pageData: { product: {}, quantity: 1 } })
  const {
    pageData: { product },
  } = state

  return (
      {/* will be available immediately when provided with <Link pageData={{ product }}> */}
      { ? <Typography variant="title">{}</Typography> : <Skeleton />}

Product.getInitialProps = createLazyProps(fetchFromAPI)