A deep link can open any route directly, a modal route included. When the app launches from fitlog://workouts/log, though, the workouts stack holds only the modal, and there is nothing behind it to return to. An anchor tells a stack layout which screen to load underneath. SDK 58 removed the initialRouteName navigator prop, so layouts that used it now need unstable_settings.anchor instead.
Key terms
- unstable_settings: an object exported from a layout file that holds router settings for that layout, such as
anchor. - anchor: the
unstable_settingskey that names the route serving as the base of a stack, kept behind a deep-linked modal. - withAnchor: a boolean navigation option on
Link,Redirectand the router's methods that loads the anchor below the target when navigation enters a new layout.
What a deep link leaves behind
Take a workout tracker whose src/app/workouts/ folder holds _layout.tsx (a Stack), index.tsx (the workout history) and log.tsx, presented as a modal. Tapping "Log workout" in the history screen pushes the modal over the history. Opened from a deep link without an anchor, the screen behind the modal is wiped away, and no navigation context is left.
The modal doesn't even look like one. The first screen of a native stack is always rendered as a card, whatever its presentation option says. In development, Expo Router logs that the route "is the first screen in its native stack, so it is rendered as a card" and suggests adding unstable_settings.anchor to the stack layout.
Exporting an anchor from the layout
Export unstable_settings with an anchor key from the stack's layout file, as the WorkoutsLayout example does with export const unstable_settings = { anchor: 'index' };. The value must match a route file name in that layout, without the extension. A name like 'history' also matches a history/index.tsx route. For a name that matches nothing, Expo Router throws an error that lists the available routes and tells you to set unstable_settings.anchor to the name of a route in this layout.
With anchor: 'index', Expo Router keeps the history screen in the background when it presents the modal, so fitlog://workouts/log opens the log over the history. Other routes in the stack keep their back arrow too, even after a deep link straight to them or a page reload on the web.
Each nested stack sets its own anchor in its own _layout.tsx, and that value becomes the stack's initial route. A stack nested in tabs reads the setting from its own layout file, not the tabs layout. Tabs, native tabs, drawer and top tabs can have an anchor as well, but they go back to it only when their backBehavior, the tab router option that controls how going back behaves, is 'initialRoute'. They log a warning if an anchor is set with any other backBehavior.
withAnchor for in-app navigation
The anchor is used only for deep links. During in-app navigation, the route you navigate to becomes the first route of the stack it enters. From the root home screen, a plain Link to /workouts/log enters the workouts layout with the log as its first route.
withAnchor changes that. <Link href="/workouts/log" withAnchor> loads the anchor below the target: the workouts stack starts with two routes, index first and log focused on top of it. In code, router.push('/workouts/log', { withAnchor: true }) does the same, and Redirect accepts the prop as well. It only matters when the navigation enters a new layout. When the target is the anchor itself, nothing extra is inserted.
Replacing initialRouteName
The Stack props type omits initialRouteName, so <Stack initialRouteName="index"> fails to type-check in SDK 58. To migrate, delete the prop and export unstable_settings = { anchor: 'index' } from the same layout. The stack's initial route now comes from the anchor, not from layout props.
initialRouteName as a key of unstable_settings is a separate case. Expo Router still reads it as a fallback when anchor is missing, but it is deprecated, and in development it logs a warning that points to unstable_settings.anchor. Rename the key.
Don't use anchor to choose the screen the app opens on. The launch URL decides that, and the default / URL needs an index.tsx route.
Code Examples
import { Stack } from 'expo-router';
export const unstable_settings = {
anchor: 'index',
};
export default function WorkoutsLayout() {
return (
<Stack>
<Stack.Screen name="index" options={{ title: 'History' }} />
<Stack.Screen name="log" options={{ presentation: 'modal' }} />
</Stack>
);
}import { Link } from 'expo-router';
import { StyleSheet, Text, View } from 'react-native';
export default function HomeScreen() {
return (
<View style={styles.screen}>
<Text style={styles.title}>Today</Text>
{/* Enters the workouts layout with its anchor (index) loaded below log */}
<Link href="/workouts/log" withAnchor>
Log a workout
</Link>
</View>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, padding: 16, gap: 12 },
title: { fontSize: 22, fontWeight: '700' },
});