{"record":{"id":"c182ba63c770c116","repo":"react-navigation/react-navigation","slug":"couldn-t-find-a-parent-screen-is-your-component-i","errorCode":null,"errorMessage":"Couldn't find a parent screen. Is your component inside a screen in a navigator?","messagePattern":"Couldn't find a parent screen\\. Is your component inside a screen in a navigator\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/useRoute.tsx","lineNumber":65,"sourceCode":"    : RouteProp<ParamListBase>;\n\nexport function useRoute(name?: string) {\n  if (name === undefined) {\n    const route = React.use(NavigationRouteContext);\n\n    if (route === undefined) {\n      throw new Error(\n        \"Couldn't find a route object. Is your component inside a screen in a navigator?\"\n      );\n    }\n\n    return route;\n  }\n\n  const NamedRouteContextList = React.use(NamedRouteContextListContext);\n\n  if (NamedRouteContextList === undefined) {\n    throw new Error(\n      \"Couldn't find a parent screen. Is your component inside a screen in a navigator?\"\n    );\n  }\n\n  const NamedRouteContext = NamedRouteContextList[name];\n\n  if (NamedRouteContext === undefined) {\n    throw new Error(\n      `Couldn't find a route named '${name}' in any of the parent screens. Is your component inside the correct screen?`\n    );\n  }\n\n  const route = React.use(NamedRouteContext);\n\n  return route;\n}\n","sourceCodeStart":47,"sourceCodeEnd":82,"githubUrl":"https://github.com/react-navigation/react-navigation/blob/ab1319d6bbf05eae8dc25e33cbf4dc56494e0f0c/packages/core/src/useRoute.tsx#L47-L82","documentation":"When useRoute is called with a name, React Navigation looks up a NamedRouteContextList provided by ancestor screens to find the named parent route. An undefined list means no parent screen exists at all — the component is not inside any navigator screen — so no named lookup can even be attempted.","triggerScenarios":"Calling useRoute('SomeScreen') in a component rendered outside any navigator (no parent screen in the tree); calling it at the app root or above the NavigationContainer.","commonSituations":"Components trying to read a parent navigator's route from a global header or drawer wrapper rendered outside screens; nested navigators where the consumer was moved outside the outer navigator during refactor.","solutions":["Render the component inside a screen of a navigator so parent route contexts exist.","Call plain useRoute() if you only need the current screen's route rather than a named ancestor's.","Access a parent route via navigation.getParent() semantics or restructure so the consumer is a descendant of the desired screen.","In tests, wrap with a navigator and matching nested screens."],"exampleFix":"// before\nfunction RootHeader() {\n  const parent = useRoute('Profile'); // no parent screen at all\n  return <Text>{parent.params?.name}</Text>;\n}\n\n// after\nfunction ProfileBody() { // rendered inside Profile screen\n  const parent = useRoute('Profile');\n  return <RootHeader name={parent.params?.name} />;\n}","handlingStrategy":"type-guard","validationCode":"// Ensure at least one ancestor screen before named lookup:\nconst currentRoute = navigationRef.current?.getCurrentRoute();\nif (currentRoute == null) {\n  console.warn('useRoute(name) requires being inside a navigator screen');\n}","typeGuard":"function hasParentScreen(list: unknown): list is Record<string, React.Context<unknown>> {\n  return list !== undefined && typeof list === 'object';\n}","tryCatchPattern":"let parentRoute;\ntry {\n  parentRoute = useRoute('ParentScreen');\n} catch (e) {\n  if (e.message.includes(\"Couldn't find a parent screen\")) {\n    parentRoute = useRoute(); // fall back to current route\n  } else throw e;\n}","preventionTips":["Render named-route consumers only inside screens of a mounted navigator.","Prefer plain useRoute() unless a specific ancestor route is required.","Document which components require navigator context and enforce it in code review.","Add storybook/test wrappers that supply a navigator."],"tags":["react-navigation","use-route","parent-screen","context"],"backgroundTag":"hook-called-outside-provider","analyzedSha":"ab1319d6bbf05eae8dc25e33cbf4dc56494e0f0c","analyzedAt":"2026-08-31T14:46:19.520Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}