facebook/docusaurus · error · Error

${pathname} is not associated with a category. useCurrentSid

Error message

${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.

What it means

Thrown by useCurrentSidebarCategory() when a sidebar IS present but the current pathname is not associated with any category — getSidebarBreadcrumbs returns no categories (deepestCategory is undefined). The hook explicitly documents that it should only be used on category index pages; using it on a regular doc page or a non-category route produces this. The message includes the offending pathname so you can see which route is wrong.

Source

Thrown at packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx:128

/**
 * Gets the category associated with the current location. Should only be used
 * on category index pages.
 */
export function useCurrentSidebarCategory(): PropSidebarItemCategory {
  const {pathname} = useLocation();
  const sidebar = useDocsSidebar();
  if (!sidebar) {
    throw new Error('Unexpected: cant find current sidebar in context');
  }
  const categoryBreadcrumbs = getSidebarBreadcrumbs({
    sidebarItems: sidebar.items,
    pathname,
    onlyCategories: true,
  });
  const deepestCategory = categoryBreadcrumbs.slice(-1)[0];
  if (!deepestCategory) {
    throw new Error(
      `${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.`,
    );
  }
  return deepestCategory;
}

/**
 * Gets the category associated with the current location. Should only be used
 * on category index pages.
 */
export function useCurrentSidebarSiblings(): PropSidebarItem[] {
  const {pathname} = useLocation();
  const sidebar = useDocsSidebar();
  if (!sidebar) {
    throw new Error('Unexpected: cant find current sidebar in context');
  }
  const categoryBreadcrumbs = getSidebarBreadcrumbs({
    sidebarItems: sidebar.items,

View on GitHub (pinned to 3f483e80e3)

Solutions

  1. Restrict useCurrentSidebarCategory() to category index pages only (the @theme/DocCategoryGeneratedIndexPage and similar).
  2. If used in a shared component, detect the page type first (is it a category index route?) and skip otherwise.
  3. Confirm the sidebar config actually marks the route as a category with an index page.
  4. Use the pathname in the error to locate which page is incorrectly invoking the hook.

Example fix

// before: called on every doc page
function DocHeader() {
  const cat = useCurrentSidebarCategory(); // throws on leaf docs
}
// after: only call on category index pages; use a page-type guard
function DocHeader() {
  const route = useRouteContext();
  const isCategoryIndex = route?.data?.isCategoryIndex;
  if (!isCategoryIndex) return null;
  const cat = useCurrentSidebarCategory();
  return <h1>{cat.label}</h1>;
}
Defensive patterns

Strategy: validation

Validate before calling

import useRouteContext from '@docusaurus/useRouteContext';

// Best signal that the current route is a category index page:
function useIsCategoryIndexPage() {
  const route = useRouteContext();
  return Boolean(route?.path?.includes('/category/')); // adjust to your route shape
}
// if (!useIsCategoryIndexPage()) return null;

Prevention

When it happens

Trigger: Calling useCurrentSidebarCategory() on a doc page (whose path is a leaf, not a category index); calling it on a route that lives in the sidebar but not under any category; a category whose index route was removed but the page still calls the hook.

Common situations: Reusing a category-breadcrumbs/header component across all doc pages instead of only category index pages; a doc whose slug happens not to nest under a category; refactoring sidebars so a former category is now a plain doc.

Related errors


AI-assisted analysis of facebook/docusaurus@3f483e80e3 (2026-08-12). Data as JSON: /api/errors/54a0f8013c04a970. Report an issue: GitHub.