Subchapter 22.7
references/react-navigation-to-expo-router.mdMarkdown4 KBView on GitHub
In SDK 56+, application code must not import from @react-navigation/* directly. Repoint those imports to the matching expo-router entry points. Runtime API is unchanged — only the module specifiers move.
@react-navigation/* source.expo-router (see Check for deprecated imports). If so, surface the deprecation reason and the suggested replacement to the user before continuing.@react-navigation/ references in source files, then run typecheck/build/start.@react-navigation/* packages that are no longer imported from package.json and reinstall (delete node_modules if needed).Run from the project root over your application code (replace src with the actual directory or glob):
npx expo-codemod sdk-56-expo-router-react-navigation-replace srcnpx expo-codemod sdk-56-expo-router-react-navigation-replace '**/*.{ts,tsx,js,jsx}'| React Navigation source | Expo Router target |
|---|---|
@react-navigation/native | expo-router/react-navigation |
@react-navigation/core | expo-router/react-navigation |
@react-navigation/elements | expo-router/react-navigation |
@react-navigation/routers | expo-router/react-navigation |
@react-navigation/stack | expo-router/js-stack |
@react-navigation/bottom-tabs | expo-router/js-tabs |
@react-navigation/material-top-tabs | expo-router/js-top-tabs |
@react-navigation/native-stack | No direct equivalent. Use the Stack layout from expo-router instead. |
Stack caveat: Do NOT rewrite import { Stack } from "expo-router" to expo-router/js-stack. The root Stack is the Expo Router layout component used in route files; only use expo-router/js-stack when replacing a @react-navigation/stack JS stack navigator.
If you encounter a symbol that has no replacement, ask the user to file an issue in the expo/expo repository describing what is needed and why.
A successful rewrite to expo-router/* does not guarantee the new import is the recommended one. Some symbols are re-exported as deprecated shims and the project may need to migrate further (for example, to a different expo-router API or to a first-party Expo package).
For each symbol rewritten in step 2:
node_modules (e.g., node_modules/expo-router/build/react-navigation.d.ts, js-stack, js-tabs, js-top-tabs).@deprecated JSDoc tag on the named export, or a runtime deprecation warning in the implementation file.@react-navigation/* imports remain in source files.@react-navigation/* entries remain in package.json.@react-navigation/* errors.