How to fix initialRouteName in Expo
If you are building a React Native app with Expo and you are facing the issue of initialRouteName not taking effect with deep linking, try this:
Move the unstable_settings object with initialRouteName to the layout file of your route group, not root layout file.
Say you have a route group like (tabs) and the index.tsx route is placed inside it. You want to set the initialRouteName to that index.tsx file.
But, the initialRouteName is set in the root layout file, so it’s not taking effect.
Here’s the correct location for the initialRouteName:
app/
├── _layout.tsx # Root layout (don't put initialRouteName here)
└── (tabs)/
├── _layout.tsx # Tab group layout (put initialRouteName here)
├── index.tsx # Your initial route
└── profile.tsx
Now, the initialRouteName will be set to the index.tsx route that is inside the (tabs) route group.