Shopify Storefront API Menu: Map URLs to Your Routes

The Storefront API menu query takes a menu handle such as main-menu and returns the items a merchant built in the Shopify admin’s menu editor, nested up to three levels. Every item carries a title, a type, an absolute url on the shop’s own domain and an optional resource. A headless storefront has to turn those into its own routes before rendering a single link.

The query is the easy part. Most of the bugs come after it: links that send shoppers back to the Online Store theme, collection links that lose their tag filter, and a header that renders empty because a handle changed. This post covers the query against Storefront API 2026-10 (the latest stable version as of November 2026, per Shopify’s versioning page) and the mapping code we put after it.

What does the Storefront API menu query return?

menu(handle: String!) returns a Menu with handle, id, title, itemsCount and items. Each MenuItem has id, title, type, url, resourceId, resource, tags and its own items. The MenuItem reference lists unauthenticated_read_content as the required access scope, so check that box on the token if the menu comes back with an access error.

There is no recursion in GraphQL, so you spell out the depth. Shopify’s admin allows a top-level item plus two levels of drop-downs (help centre), which means three levels of items covers any menu a merchant can build:

query HeaderMenu($handle: String!) {
  shop {
    primaryDomain {
      host
    }
  }
  menu(handle: $handle) {
    title
    itemsCount
    items {
      ...MenuLink
      items {
        ...MenuLink
        items {
          ...MenuLink
        }
      }
    }
  }
}

fragment MenuLink on MenuItem {
  id
  title
  type
  url
  tags
  resource {
    __typename
    ... on Collection { handle }
    ... on Product { handle }
    ... on Page { handle }
    ... on Blog { handle }
    ... on Article { handle blog { handle } }
    ... on ShopPolicy { handle }
    ... on Metaobject { handle type }
  }
}

The shop.primaryDomain.host field is there for the mapping step below. The fragment asks for a handle on each of the seven members of the MenuItemResource union: Article, Blog, Collection, Metaobject, Page, Product and ShopPolicy. We validated this query against the 2026-10 schema.

An unknown handle does not raise an error. The return type is a nullable Menu, and mock.shop answers a made-up handle with "menu": null and a 200, which is why a renamed menu shows up as a blank header and not as an exception in your logs.

Why do menu URLs point at the Online Store?

Because the menu belongs to the Online Store, and url is where the item lives there. Ask mock.shop’s demo store for main-menu and the first item comes back as:

{
  "title": "Men",
  "type": "COLLECTION",
  "url": "https://demostore.hydrogen.mock.shop/collections/men",
  "tags": [],
  "resource": null
}

Render that url as-is and a shopper on your headless site clicks through to the theme storefront, or to a password page if the theme is locked. Shopify’s own Hydrogen example handles this in Header.tsx: if the URL contains myshopify.com, the public store domain or the primary domain URL, it keeps only the pathname. Anything else is treated as external.

That works when your routes mirror Shopify’s paths. It breaks when they do not. It is also a substring match, so an external link such as a partner’s ?ref=example.myshopify.com tracking URL contains the shop domain and gets cut down to a local path that does not exist.

Note resource: null in that response as well. On mock.shop every resource we requested came back null in November 2026, collection links included. Whatever the cause on a given store, the mapping code cannot assume resource is present.

How do you map menu items to headless routes?

Use the resource when it is there, and fall back to the URL’s path when the host is one of the shop’s own. The MenuItemType enum has 13 values (ARTICLE, BLOG, CATALOG, COLLECTION, COLLECTIONS, CUSTOMER_ACCOUNT_PAGE, FRONTPAGE, HTTP, METAOBJECT, PAGE, PRODUCT, SEARCH, SHOP_POLICY), but only seven types have a resource behind them. FRONTPAGE, SEARCH, COLLECTIONS, CATALOG and CUSTOMER_ACCOUNT_PAGE give you a URL and nothing else. HTTP is whatever the merchant typed.

type MenuResource =
  | { __typename: 'Collection' | 'Product' | 'Page' | 'Blog' | 'ShopPolicy'; handle: string }
  | { __typename: 'Article'; handle: string; blog: { handle: string } }
  | { __typename: 'Metaobject'; handle: string; type: string };

export type MenuLink = {
  id: string;
  title: string;
  type: string;
  url: string | null;
  tags: string[];
  resource: MenuResource | null;
  items?: MenuLink[];
};

const ROUTES: Record<string, string> = {
  Collection: '/collections/',
  Product: '/products/',
  Page: '/pages/',
  Blog: '/blogs/',
  ShopPolicy: '/policies/',
};

/** Turn a Storefront API menu item into an href for this storefront. */
export function menuHref(item: MenuLink, shopHosts: Set<string>): string | null {
  const r = item.resource;

  // A tag-filtered collection link carries its filter in the URL, not the handle.
  if (r && item.tags.length === 0) {
    if (r.__typename === 'Article') return `/blogs/${r.blog.handle}/${r.handle}`;
    if (r.__typename === 'Metaobject') return `/${r.type}/${r.handle}`;
    return ROUTES[r.__typename] + r.handle;
  }

  if (!item.url) return null;
  const url = new URL(item.url);
  return shopHosts.has(url.hostname) ? url.pathname + url.search : item.url;
}

Build shopHosts from the values you already have: your *.myshopify.com domain from config and shop.primaryDomain.host from the query. Comparing hostname exactly avoids the substring trap. Run against the mock.shop menu, this returns /collections/men, /collections/women, /collections/unisex, /collections and /blogs/news, all from the URL fallback.

The ROUTES table is where your router’s opinions go. If products live at /p/:handle on your site, change it there once. Metaobject entries have no single Shopify path a headless site has to copy, so the sample puts them under the metaobject type; point that at whatever route renders them.

What are menu item tags for?

The MenuItem reference describes tags as “the menu item’s tags to filter a collection”. A merchant can link to a collection narrowed to a tag, and a path built from the collection handle alone would drop that filter. The function above skips the resource whenever tags are present and uses the URL path, which keeps the filter in the link. If your collection route filters by something else, read item.tags there and build the query string yourself.

How should a headless storefront fetch and cache the menu?

Fetch it on the server with the rest of the layout data, and cache it for a long time. Menus change when a merchant edits them, which is rarely. The example app in Shopify’s Hydrogen repo (the 2026.10 SDK line, as of November 2026) runs the header menu query with Cache.long() in root.tsx, passes main-menu and footer as the two handles, and defers the footer query because it sits below the fold. Our Hydrogen caching write-up covers what those cache strategies mean in practice.

Outside Hydrogen it is a plain POST:

import { HEADER_MENU_QUERY } from './queries'; // the HeaderMenu query above

const domain = process.env.PUBLIC_STORE_DOMAIN!; // example.myshopify.com

const res = await fetch(`https://${domain}/api/2026-10/graphql.json`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Storefront-Access-Token': process.env.PUBLIC_STOREFRONT_API_TOKEN!,
  },
  body: JSON.stringify({ query: HEADER_MENU_QUERY, variables: { handle: 'main-menu' } }),
});

const { data } = await res.json();
if (!data.menu) throw new Error('Menu "main-menu" not found');

const shopHosts = new Set([domain, data.shop.primaryDomain.host]);

Throwing on a null menu is a choice. We would rather a build or a server log shout about a renamed handle than ship a header with no links. If you do keep a fallback menu, log when it is used.

The Hydrogen example also wraps the query in @inContext(language:, country:), the same directive our post on @inContext and local prices covers. If a store translates its menus, pass the language through so the titles match the rest of the page.

When should you skip the menu query?

Use the menu query when a merchant needs to edit the header and footer without waiting for a deploy, which describes most stores.

Hard-code the navigation when the links are fixed by the product rather than by marketing: an account area, a checkout-adjacent flow, or a single-product site with three pages. A query that can return null, and URLs you have to rewrite, buy you nothing there.

If you do use it, keep the mapping in one function like menuHref. Your routes will change long before the menu fields do, and one ROUTES table is quicker to fix than hrefs built in five components.

We build headless Shopify storefronts, on Hydrogen and on Next.js, and wiring merchant-editable navigation to custom routes is part of most of them. Our Shopify development work covers that alongside the rest of the build.

Need this built properly?

Get in touch

Hack the planet!