{"record":{"id":"e8cb612c004a4fe7","repo":"expo/expo","slug":"expo-router-error-expected-navigation-state-to-be","errorCode":null,"errorMessage":"Expo Router Error: Expected navigation state to begin with one of [${getRootStackRouteNames().join(', ')}] routes","messagePattern":"Expo Router Error: Expected navigation state to begin with one of \\[(.+?)\\] routes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/expo-router/src/link/preview/HrefPreview.tsx","lineNumber":151,"sourceCode":"        alignItems: 'center',\n        gap: 8,\n        backgroundColor: 'white',\n      }}>\n      <Text style={{ fontWeight: '600', fontSize: 24 }}>Invalid preview</Text>\n      <Text style={{ fontWeight: '200', fontSize: 14 }}>{pathname}</Text>\n    </View>\n  );\n}\n\nfunction getParamsAndNodeFromHref(\n  hrefState: ResultState,\n  rootRouteNode: RouteNode | null | undefined\n) {\n  const index = hrefState?.index ?? 0;\n  if (hrefState?.routes[index] && hrefState.routes[index].name !== INTERNAL_SLOT_NAME) {\n    const error = `Expo Router Error: Expected navigation state to begin with one of [${getRootStackRouteNames().join(', ')}] routes`;\n    if (process.env.NODE_ENV !== 'production') {\n      throw new Error(error);\n    } else {\n      console.warn(error);\n    }\n  }\n  const initialState = hrefState?.routes[index]?.state;\n  const { routeNode, params } = findRouteNodeAndParamsForState(rootRouteNode, initialState);\n\n  // Linking has already parsed these values into the public search-param shape.\n  return { params: params as UnknownOutputParams, routeNode, state: initialState };\n}\n\nconst displayWarningForProp = (prop: string) => {\n  if (process.env.NODE_ENV !== 'production') {\n    console.warn(\n      `navigation.${prop} should not be used in a previewed screen. To fix this issue, wrap navigation calls with 'if (!isPreview) { ... }'.`\n    );\n  }\n};","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/expo/expo/blob/7da61120be99bcd9cc2e5dbdba6d803c21b5c68b/packages/expo-router/src/link/preview/HrefPreview.tsx#L133-L169","documentation":"When pre-parsing an href into navigation state, `getParamsAndNodeFromHref` expects the root-level route name to be one of the root stack's route names (or the internal slot). Anything else means the href cannot be mapped onto the root navigator.","triggerScenarios":"An href string (passed to `<Link>`/`router`/`HrefPreview`) resolves to a state whose first route name is not a root-stack route name and not INTERNAL_SLOT_NAME; dev throws, production warns.","commonSituations":"Typing an absolute href to a route that doesn't exist at the root (e.g. group/slot mismatch); using `../`-style or `+`-prefixed paths incorrectly; hrefs referencing routes removed after refactoring.","solutions":["Check the href points to an existing route name at the root stack level","Verify route groups `(group)` syntax — group names are not part of the URL","Run `npx expo-router typed-routes` or inspect the route tree to confirm valid paths","In dev the throw surfaces immediately; fix the href rather than suppressing the warning"],"exampleFix":"// before\n<Link href=\"/(tabs)/unknown/sheet\" />\n// after\n<Link href=\"/unknown\" /> // route that exists at the root stack","handlingStrategy":"validation","validationCode":"// validate href before passing to Link/router\nconst validRootNames = ['index', '(tabs)', '(app)']; // your root stack route names\nif (!validRootNames.some(n => href.startsWith('/' + n.replace(/\\(.*\\)/, '')))) console.warn('href does not resolve to a root route:', href);","typeGuard":"function isResolvedHref(href: string): boolean { return !href.startsWith('//') && !href.includes('..'); }","tryCatchPattern":"try { parseHref(href); } catch (e) { if (String(e).includes('Expected navigation state')) console.warn('Unresolvable href:', href); }","preventionTips":["Use typed routes (`experiments.typedRoutes`) so invalid hrefs fail at compile time","Remember group names `(group)` never appear in hrefs","Verify hrefs after renaming/deleting route files"],"tags":["expo-router","navigation","href"],"backgroundTag":"invalid-argument-value","analyzedSha":"7da61120be99bcd9cc2e5dbdba6d803c21b5c68b","analyzedAt":"2026-09-09T16:01:44.845Z","contentChangedAt":"2026-09-09T16:01:44.845Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}