/sitecore-content-sdk-nextjs-app-router:content-sdk-app-router-component-level-navigationfrom Sitecore Content SDK - Next.js App Router
Provides a component-level GraphQL navigation pattern for Sitecore Content SDK App Router apps. Server fetches top levels, client lazy-loads deeper ones via a route handler. Use for main, footer, or sidebar nav, or when the SXA nav resolver returns empty.
Ships in Sitecore Content SDK - Next.js App Router. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A navigation that you actually control: queries you can read, types you can refactor, layout you can predict. Avoids the SXA Navigation Content Resolver (opaque, parameter-driven, fragile) and Integrated GraphQL on the rendering (query lives in Sitecore, hard to version). Instead the React component owns its data fetching via the SDK's GraphQL client.
Navigation Content Resolver is misbehaving, returning empty arrays, or its parameters (LevelFrom/LevelTo/Filter) are hard to reason about.NavigationTitle / NavigationFilter, not the nav rendering itself).Server-side initial render:
┌─────────────────────────────────────────────┐
│ NavigationCustom.tsx (Server Component) │
│ client.getData<NavLevel1Response>( │
│ NAV_LEVEL_1_QUERY, { root, language }) │
│ ↓ returns root + L1 children + │
│ hasChildren flag per child │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ NavBranch.tsx (Client Component) per item │
│ Renders link + chevron (if hasChildren) │
│ On hover/focus → ensureLoaded() → │
│ fetch('/api/nav-children?parent=...') │
│ Caches result in component state │
│ Renders dropdown with recursive NavBranch │
└─────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────┐
│ /api/nav-children/route.ts (Route Handler) │
│ GET ?parent=...&language=...&maxItems=20 │
│ client.getData<NavBranchResponse>( │
│ NAV_BRANCH_QUERY, { parent, language }) │
│ Returns JSON array of child items │
│ NO router.refresh() side-effect │
└─────────────────────────────────────────────┘
Recursion: each NavBranch can itself render child NavBranch components inside its dropdown. Each child can lazy-load ITS children via the same route handler. The pattern scales to L3, L4, … without code changes — the only knob is the rendering parameter that caps depth.
Rendering item at /sitecore/layout/Renderings/Project/<project>/NavigationCustom:
componentName = NavigationCustomDatasource Location = query:$site|query:$sharedSitesParameters Template = the new Parameters Template (next step)OtherProperties = IsRenderingsWithDynamicPlaceholders=trueParameters Template at /sitecore/templates/Project/<project>/Rendering Parameters/NavigationCustom Parameters with shared fields:
| Field | Type | Notes |
|---|---|---|
Level | Droplist 1|2 | Default 1. Do NOT name this Levels — that name collides with base-template inheritance on some Sitecore versions and the field becomes invisible in Pages. Level (singular) is safe. |
MaxItems | Single-Line Text | Default 20 — per-level pagination cap; keeps Edge complexity bounded. |
Class | Single-Line Text | Optional CSS hook for layout variants. |
Add to Available Renderings under /sitecore/content/<tenant>/<site>/Presentation/Available Renderings/Navigation.
Place on a page in Pages Editor:
/Home).Level = 2 for dropdowns; Level = 1 for flat clickable nav.(Optional) Headless Variants if you want author-selectable visual treatments — skip for v1.
Critical: only the Sitecore-registered .tsx lives under src/components/<Component>/. All support files (types, queries, sub-components, route handlers) live elsewhere or sitecore-tools generate-map will register them as separate Sitecore renderings or variants. See content-sdk-component-naming-traps.
src/
components/
NavigationCustom/
NavigationCustom.tsx # ONLY this file — Server Component, registered by gen-map
lib/
navigation/
types.ts # NavItem, NavLevel1Response, NavBranchResponse, navLabel(), isNavVisible()
queries.ts # NAV_LEVEL_1_QUERY, NAV_BRANCH_QUERY (string literals)
nav-branch.tsx # 'use client' — recursive NavBranch with hover/focus/click + lazy fetch
app/
api/
nav-children/
route.ts # GET handler — uses SitecoreClient.getData, returns JSON
query NavLevel1($root: String!, $language: String!, $maxItems: Int = 20) {
item(path: $root, language: $language) {
id
path
displayName
navTitle: field(name: "NavigationTitle") { value }
url { path }
navFilter: field(name: "NavigationFilter") { value }
children(first: $maxItems, hasLayout: true) {
results {
id
path
displayName
navTitle: field(name: "NavigationTitle") { value }
url { path }
navFilter: field(name: "NavigationFilter") { value }
hasChildren(hasLayout: true)
}
}
}
}
hasLayout: true — excludes data items, datasources, settings nodes. Only pages.hasChildren(hasLayout: true) — boolean flag per L1 item. Lets the client decide whether to render an expandable chevron WITHOUT a round-trip. Crucial for UX.url { path } is the public-facing URL (the visitor href). NOT the Sitecore tree path (path) — that's for downstream fetches only.first: 20 with all these field-lookups against a real SitecoreAI tenant. See sitecoreai-edge-graphql-capture for limits.// src/app/api/nav-children/route.ts
import { NextResponse } from 'next/server';
import client from 'src/lib/sitecore-client';
import { NAV_BRANCH_QUERY } from 'src/lib/navigation/queries';
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const parent = searchParams.get('parent');
const language = searchParams.get('language') ?? 'en';
if (!parent) {
return NextResponse.json({ error: 'parent required' }, { status: 400 });
}
const result = await client.getData(NAV_BRANCH_QUERY, { parent, language, maxItems: 20 });
return NextResponse.json(result.item?.children.results ?? []);
}
query NavBranch($parent: String!, $language: String!, $maxItems: Int = 20) {
item(path: $parent, language: $language) {
children(first: $maxItems, hasLayout: true) {
results {
id
path
displayName
navTitle: field(name: "NavigationTitle") { value }
url { path }
navFilter: field(name: "NavigationFilter") { value }
hasChildren(hasLayout: true)
}
}
}
}
WHY a route handler, not a Server Action:
router.refresh() after completion (designed for mutations — re-fetch the RSC tree to reflect server state changes).This is a Next.js architectural rule, not a Sitecore quirk: reads → route handler, mutations → server action.
Key behavior, distilled:
'use client';
export function NavBranch({ item, language, maxItems, remainingLevels }) {
const [children, setChildren] = useState<NavItem[] | null>(null);
const [loading, setLoading] = useState(false);
const [open, setOpen] = useState(false);
const fetchedRef = useRef(false); // de-dupe fetch
const closeTimerRef = useRef(null); // hover intent-delay
const expandable = item.hasChildren && remainingLevels > 0;
const ensureLoaded = useCallback(async () => {
if (fetchedRef.current) return;
fetchedRef.current = true;
setLoading(true);
try {
const url = `/api/nav-children?parent=${encodeURIComponent(item.path)}&language=${language}&maxItems=${maxItems}`;
const r = await fetch(url, { headers: { Accept: 'application/json' } });
if (!r.ok) { fetchedRef.current = false; setChildren([]); return; }
const data = await r.json();
setChildren(data.filter(isNavVisible));
} finally { setLoading(false); }
}, [item.path, language, maxItems]);
const handleOpen = useCallback(() => {
if (closeTimerRef.current) { clearTimeout(closeTimerRef.current); closeTimerRef.current = null; }
setOpen(true);
void ensureLoaded();
}, [ensureLoaded]);
// 150ms intent-delay — don't close on brief mouseleave (user travelling toward dropdown)
const handleClose = useCallback(() => {
if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
closeTimerRef.current = setTimeout(() => { setOpen(false); closeTimerRef.current = null; }, 150);
}, []);
return (
<li
className="relative"
onMouseEnter={expandable ? handleOpen : undefined}
onMouseLeave={expandable ? handleClose : undefined}
onFocus={expandable ? handleOpen : undefined}
onBlur={(e) => {
if (expandable && !e.currentTarget.contains(e.relatedTarget as Node | null)) handleClose();
}}
>
<div className="flex items-center">
<Link href={item.url.path || '#'}>{navLabel(item)}</Link>
{expandable && <button onClick={() => open ? handleClose() : handleOpen()} aria-expanded={open}>▼</button>}
</div>
{expandable && open && (
<ul
role="menu"
// top-full FLUSH with parent's bottom — NO mt-*. Any visible gap here
// causes mouseleave on <li> during cursor traversal, triggering flicker.
className="absolute left-0 top-full z-50 min-w-48 ..."
>
{loading ? <li>Loading…</li> :
children?.length ? children.map(c => <NavBranch key={c.id} item={c} language={language} maxItems={maxItems} remainingLevels={remainingLevels - 1} />)
: <li>No items</li>}
</ul>
)}
</li>
);
}
hasChildren flag in L1 query: lets the client render the expandable chevron before any L2 fetch. Without it, you'd have to either fetch all L2 upfront (defeats lazy load) or render every L1 with a chevron (UI lies about expandability). Item.hasChildren(hasLayout: Boolean) is a cheap boolean.
Route Handler for the L2 read (the bug we hit and fixed): Server Actions trigger router.refresh() → wipes client state → endless loading flicker. Route Handler returns JSON with zero React side-effect. Universal rule: client-triggered reads → route handler.
Hover intent-delay (150ms): brief mouseleaves (e.g., crossing a tiny gap) don't immediately close. Re-entering within 150ms cancels the close. Standard popover pattern.
No-gap dropdown positioning (top-full, no mt-*): the dropdown must be flush with the parent <li>'s bottom. Any visible CSS gap creates a zone where mouse is OUTSIDE <li>'s bbox AND outside the dropdown's DOM — triggers mouseleave on the <li> → close → flicker. Internal padding (p-1) provides visual breathing room.
Recursive NavBranch (each branch fetches its own children): no flat tree code, no per-level branching. Same component works for L1, L2, L3, … The only stop condition is remainingLevels === 0.
NavigationFilter respect (isNavVisible): items with a non-empty NavigationFilter field value are hidden. Matches SXA's "any filter set = hidden from default nav" convention. Conservative default; can be made configurable later.
NavigationTitle override (navLabel): per-item author override of the link label. Falls back to displayName when not set. Standard Sitecore convention.
Datasource = root, NOT a rendering parameter: one mechanism, no overlap. Author picks root via Pages' Content tab. Tested earlier with a Root rendering parameter — added confusion ("which wins?"), removed.
Helper files live OUTSIDE src/components/: types, queries, route handler, NavBranch client component all under src/lib/navigation/ (or src/app/api/ for the route handler). Inside src/components/NavigationCustom/, only the Sitecore-registered .tsx. Otherwise gen-map registers helpers as Sitecore renderings or variants. See content-sdk-component-naming-traps.
Empirically tested against SitecoreAI Edge on 2026-05-27:
first: 20 + full field() lookups + hasChildren) → ✅ worksfirst: 5 + minimal fields, no field()) → ✅ worksfirst: 5 + any field() lookups) → ❌ "Query is too complex"So a SINGLE L0+L1+L2 query is impractical with full fidelity. Per-branch lazy fetch sidesteps this entirely — each branch's children query has the same shape as the L1 query and stays within limits.
See sitecoreai-edge-graphql-capture for the full Edge limits catalogue.
router.refresh(); reads don't want that. Universal Next.js rule, especially load-bearing here.hasChildren(hasLayout: true) on the L1 query so chevrons can render without a second fetch.<ul> flush with parent <li> — top-full, no mt-*. A visible gap causes endless mouseleave flicker. Internal padding for visual breathing room.field(name:) only at root + L1. Don't try to nest field() lookups at L2 in a single query — Edge will reject as too complex.hasLayout: true on every children call. Excludes data items, datasources, and structural nodes that shouldn't appear in a navigation.url { path } for hrefs, NOT path. url.path is the public URL; path is the Sitecore tree path (for downstream queries only).Root rendering parameter — it duplicates the mechanism and creates "which wins?" ambiguity.types.ts, queries.ts, nav-branch.tsx, actions.ts-style fetchers) live OUTSIDE src/components/<Component>/. Put them in src/lib/<feature>/ or src/app/api/.Level (singular), not Levels. Plural collides with base-template inheritance on some Sitecore configurations and becomes invisible in Pages.isNavVisible filter on every result set — both server-side (L1) and client-side (L2+ after fetch).client.getData call runs server-side; Next.js can cache it via the standard fetch cache (with appropriate next: { revalidate } if needed).useRef/useState. Re-hover doesn't re-fetch. No global cache needed for v1.router.refresh() side-effect breaks client state for reads.hasLayout: true — your nav will fill with datasources and settings items.<code type="text/sitecore">) which can interfere with mouse handlers. Test in the live published page, not the editor preview.src/components/<Component>/. Even though it feels right, gen-map will register them as Sitecore renderings or as variants of your main component, polluting the map.Level=2) won't propagate until publish + ~30s.view-source HTML).GET /api/nav-children?parent=... per branch on first hover. None on re-hover.router.refresh() events on hover (proves you're using a route handler, not a server action).content-sdk-resolver-patterns — why this pattern beats Navigation Content Resolver and Integrated GraphQL for navigation.content-sdk-component-naming-traps — the rule that forces helper files out of src/components/<Component>/.sitecoreai-edge-graphql-capture — Edge complexity limits this pattern works around.content-sdk-debug-layout-probe — for verifying layout response shape when integrating with Sitecore.content-sdk-variants-vs-siblings — for adding visual variants (e.g., NavigationCustom.MegaMenu.tsx).content-sdk-app-router-graphql-data-fetching — the SDK's client.getData API used here.src/lib/navigation/{types,queries,nav-branch}, one route handler — and the code blocks in this skill are its load-bearing parts verbatim. (The component was called Navigation_Custom when first built; it is NavigationCustom here because content-sdk-component-naming-traps trap 6 makes an underscored name version-sensitive.)sitecoreai-edge-graphql-capture for the empirical ceiling.SitecoreClient.getData<T>(query, variables, fetchOptions) — node_modules/@sitecore-content-sdk/content/types/client/sitecore-client.d.ts:122.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
17 skills in this plugin
/content-sdk-app-router-atom-createWrites a Content SDK atom (beta.atoms): atom vs component, field schemas and enum tokens, renderer, catalog and registry keys, container slots, lock lifecycle, mock-MMS proof. Use when adding or changing an atom. Not wiring atoms into an app./content-sdk-app-router-atomsContent SDK Atoms (beta.atoms only): catalog, atomsConfig, ComponentRef rendering, lock CI gate, runtime CSS, Content Kit install, null-render traps. Use when wiring atoms or a low-code component renders nothing. Not code components or stable apps./content-sdk-app-router-cache-components-and-osrnpx claudepluginhub chris1415/sitecore-skills-pocs --plugin sitecore-content-sdk-nextjs-app-routerOther plugins' skills for the same job