File-based routing framework.
Navigation between screens.
App directory
Root layout
app/_layout.tsx
file defines shared UI elements such as headers and tab bars.index
files
Route file
Stack
Foundation to navigate between different screens in an app.
Stack
is defined in the _layout.tsx
:
import { Stack } from 'expo-router'; export default function RootLayout() { return ( <Stack> <Stack.Screen name="index" options={{ title: 'Home' }} /> <Stack.Screen name="about" options={{ title: 'About' }} /> </Stack> ); }
On Android, a stacked route animates on top of the current screen On iOS, a stacked route animates from the right
Link
You can navigate from page to page using Link
component:
import { Text, View, StyleSheet } from 'react-native'; import { Link } from 'expo-router'; export default function Index() { return ( <View style={styles.container}> <Text style={styles.text}>Home screen</Text> <Link href="/about" style={styles.button}> Go to About screen </Link> </View> ); }
(tabs)
Sub directorySpecial directory to group routes together and display them in a bottom tab bar.
(tabs)/_layout.tsx
is separate from the root layout.