{"record":{"id":"54a0f8013c04a970","repo":"facebook/docusaurus","slug":"pathname-is-not-associated-with-a-category-use","errorCode":null,"errorMessage":"${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.","messagePattern":"(.+?) is not associated with a category\\. useCurrentSidebarCategory\\(\\) should only be used on category index pages\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx","lineNumber":128,"sourceCode":"\n/**\n * Gets the category associated with the current location. Should only be used\n * on category index pages.\n */\nexport function useCurrentSidebarCategory(): PropSidebarItemCategory {\n  const {pathname} = useLocation();\n  const sidebar = useDocsSidebar();\n  if (!sidebar) {\n    throw new Error('Unexpected: cant find current sidebar in context');\n  }\n  const categoryBreadcrumbs = getSidebarBreadcrumbs({\n    sidebarItems: sidebar.items,\n    pathname,\n    onlyCategories: true,\n  });\n  const deepestCategory = categoryBreadcrumbs.slice(-1)[0];\n  if (!deepestCategory) {\n    throw new Error(\n      `${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.`,\n    );\n  }\n  return deepestCategory;\n}\n\n/**\n * Gets the category associated with the current location. Should only be used\n * on category index pages.\n */\nexport function useCurrentSidebarSiblings(): PropSidebarItem[] {\n  const {pathname} = useLocation();\n  const sidebar = useDocsSidebar();\n  if (!sidebar) {\n    throw new Error('Unexpected: cant find current sidebar in context');\n  }\n  const categoryBreadcrumbs = getSidebarBreadcrumbs({\n    sidebarItems: sidebar.items,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-plugin-content-docs/src/client/docsUtils.tsx#L110-L146","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Restrict useCurrentSidebarCategory() to category index pages only (the @theme/DocCategoryGeneratedIndexPage and similar).","If used in a shared component, detect the page type first (is it a category index route?) and skip otherwise.","Confirm the sidebar config actually marks the route as a category with an index page.","Use the pathname in the error to locate which page is incorrectly invoking the hook."],"exampleFix":"// before: called on every doc page\nfunction DocHeader() {\n  const cat = useCurrentSidebarCategory(); // throws on leaf docs\n}\n// after: only call on category index pages; use a page-type guard\nfunction DocHeader() {\n  const route = useRouteContext();\n  const isCategoryIndex = route?.data?.isCategoryIndex;\n  if (!isCategoryIndex) return null;\n  const cat = useCurrentSidebarCategory();\n  return <h1>{cat.label}</h1>;\n}","handlingStrategy":"validation","validationCode":"import useRouteContext from '@docusaurus/useRouteContext';\n\n// Best signal that the current route is a category index page:\nfunction useIsCategoryIndexPage() {\n  const route = useRouteContext();\n  return Boolean(route?.path?.includes('/category/')); // adjust to your route shape\n}\n// if (!useIsCategoryIndexPage()) return null;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve useCurrentSidebarCategory() for category index pages only.","Detect category index routes before calling.","Use the pathname in the error to find the misused page."],"tags":["docs","sidebar","category","routing","react-hook"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}