> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackfront.digital/llms.txt
> Use this file to discover all available pages before exploring further.

# Navigation menus

Read Shopify's navigation menus as an app-agnostic tree: routes, handles,
images, external links and optional mega-menu columns. Menus are public
Storefront data — no customer session required.

```tsx theme={null}
import {
  useMenu,
  useMenus,
  usePrefetchMenu,
  flattenMenu,
  findMenuItemByHandle,
} from '@stackfront/react-native-shopify';
```

## One menu

```tsx theme={null}
const { menu, nodes, loading, error, refetch } = useMenu('main-menu');

<FlashList
  data={nodes}
  renderItem={({ item }) => <DrawerItem node={item} />}
  keyExtractor={(item) => item.id}
/>;
```

`menu` is the normalized Shopify menu (raw tags, resource ids). `nodes` is
the UI-ready tree (`NavigationNode[]`). Mapping happens on render, so it costs
no extra request.

## Several menus in one request

The Storefront API has a single `menu(handle:)` root and **no** `menus(...)`
batch field. `useMenus` still makes **one** round trip by generating GraphQL
aliases for the requested handles.

```tsx theme={null}
const { menus } = useMenus(['main-menu', 'footer']);
menus['main-menu']?.items; // normalized menu or null
```

## Prefetch before navigating

```tsx theme={null}
const prefetchMenu = usePrefetchMenu();

<Pressable
  onPressIn={() => prefetchMenu('main-menu')}
  onPress={openDrawer}
/>;
```

`useMenu('main-menu')` then renders from the same cache with no spinner.

## Navigation node

```ts theme={null}
interface NavigationNode {
  id: string;
  title: string;
  url: string;
  type:
    | 'PRODUCT' | 'COLLECTION' | 'COLLECTIONS' | 'CATALOG' | 'FRONTPAGE'
    | 'PAGE' | 'BLOG' | 'ARTICLE' | 'SEARCH' | 'SHOP_POLICY' | 'METAOBJECT'
    | 'CUSTOMER_ACCOUNT_PAGE' | 'EXTERNAL' | 'LINK';
  isExternal: boolean;
  route: string;        // app-agnostic: '/products/tee', '/collections/tees'
  handle?: string;
  resourceId?: string;
  resourceHandle?: string;
  icon?: string;
  image?: { url: string; altText?: string; width?: number; height?: number };
  badge?: { text: string; variant?: string };
  isMegaMenu: boolean;
  columns?: NavigationNode[][];
  theme?: { textColor?: string; backgroundColor?: string; highlightColor?: string };
  children: NavigationNode[];
}
```

### Routes, not deep links

`route` is always a plain path (`/products/<handle>`,
`/collections/<handle>`, `/collections/all`, `/pages/<handle>`,
`/blogs/<blog>/<article>`, `/policies/<handle>`, `/search`, `/account`) or
the original URL for external/unknown links. Map it onto your own navigator —
the SDK never hard-codes a `myapp://` scheme.

Shopify returns **absolute** storefront URLs
(`https://shop.myshopify.com/products/tee`). Those are recognized as internal
resources, not external links; `isExternal` is reserved for off-store URLs
whose path the SDK cannot route.

### Mega menus

A node is a mega menu when `children.length >= 6`, or when you opt in with an
override. `columns` is then provided:

* if any child has its own children, each child becomes a column header
  followed by its descendants;
* otherwise children are chunked into columns of 4.

```tsx theme={null}
const { menu } = useMenu('main-menu');
const tree = buildNavigationTree(menu!, {
  'gid://shopify/MenuItem/123': {
    title: 'Sale',
    badge: { text: '50% off', variant: 'sale' },
    isMegaMenu: true,
  },
});
```

Overrides are keyed by item **id** or **url** and support `title`, `icon`,
`badge`, `image`, `theme`, `isMegaMenu`.

## Tree helpers

```ts theme={null}
flattenMenu(nodes);                       // depth-first NavigationNode[]
findMenuItem(nodes, (n) => n.type === 'PAGE');
findMenuItemByHandle(nodes, 'tees');      // last route segment
getMenuBreadcrumbs(nodes, itemIdOrUrl);   // root → target path
```

All are pure and exported (`buildNavigationTree`, `normalizeMenu`,
`parseMenuUrl` as well), so tests and custom navigators can reuse them.

## Service API

```ts theme={null}
const { menus: menuService } = useStackfront();

const main = await menuService.getMenu('main-menu');       // SdkMenu | null
const all = await menuService.getMenus(['main-menu', 'footer']);
// { 'main-menu': SdkMenu | null, footer: SdkMenu | null } — one request
```

An unknown handle resolves to `null`; an empty handle makes no request.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.