Expo Router
expo-router is a navigation library provided by Expo that simplifies the implementation of navigation in React Native applications. It is built on top of React Navigation, a widely used navigation library, and abstracts away much of the complexity involved in managing navigation state and transitions between screens.
Navigation in Expo Router is expressed declaratively, utilizing components to define the flow of the application. This approach makes it intuitive for developers to structure their navigation hierarchy.
Conventional React Native projects typically adopt a structure where a sole root component is commonly specified in either ./App.js or ./index.js. Within the context of Expo Router, an alternative approach is offered through the utilization of the Root Layout, located in app/_layout.tsx in our Demo. Thereby, the _layout section of our app handles the overall structure and navigation setup.
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import { Stack, ThemeProvider } from 'expo-router';import * as SplashScreen from 'expo-splash-screen';import * as React from 'react';import { StyleSheet } from 'react-native';import FlashMessage from 'react-native-flash-message';import { GestureHandlerRootView } from 'react-native-gesture-handler';import { KeyboardProvider } from 'react-native-keyboard-controller';import { APIProvider } from '@/api';
import interceptors from '@/api/common/interceptors';import { AnalyticsProvider } from '@/components/providers/analytics';import { useAnalyticsScreenTracking, useAnalyticsSessionReset } from '@/components/providers/analytics-tracking';import { AuthProvider, useAuth } from '@/components/providers/auth';import { consoleAnalyticsProvider, hydrateAuth, loadSelectedTheme, useIsFirstTime } from '@/lib';import { getFallbackRoute } from '@/lib/auth/get-fallback-route';import { useSyncLanguageWithOS } from '@/lib/i18n';import { useThemeConfig } from '@/lib/use-theme-config';// Import global CSS fileimport '../../global.css';
export { ErrorBoundary } from 'expo-router';
export const unstable_settings = { anchor: '(app)',};
hydrateAuth();loadSelectedTheme();interceptors();// Analytics providers the app reports to. Add real vendor adapters here.const analyticsProviders = [consoleAnalyticsProvider];// Prevent the splash screen from auto-hiding before asset loading is complete.void SplashScreen.preventAutoHideAsync();// Set the animation options. This is optional.SplashScreen.setOptions({ duration: 500, fade: true,});
function AnalyticsTrackers() { useAnalyticsSessionReset(); useAnalyticsScreenTracking(); return null;}
function GuardedStack() { const { isAuthenticated } = useAuth(); const [isFirstTime] = useIsFirstTime(); const fallbackRoute = getFallbackRoute({ isFirstTime, isAuthenticated });
return ( <> <AnalyticsTrackers /> <Stack> <Stack.Protected guard={isFirstTime} redirectTo={fallbackRoute}> <Stack.Screen name="onboarding" options={{ headerShown: false }} /> </Stack.Protected>
<Stack.Protected guard={isAuthenticated} redirectTo={fallbackRoute}> <Stack.Screen name="(app)" options={{ headerShown: false }} /> <Stack.Screen name="update-password" /> </Stack.Protected>
<Stack.Protected guard={!isAuthenticated} redirectTo={fallbackRoute}> <Stack.Screen name="sign-in" options={{ headerShown: false }} /> <Stack.Screen name="sign-up" /> <Stack.Screen name="forgot-password" /> </Stack.Protected>
<Stack.Screen name="www" options={{ presentation: 'modal', title: '', }} /> </Stack> </> );}
export default function RootLayout() { useSyncLanguageWithOS();
return ( <Providers> <RouterContent /> </Providers> );}
function RouterContent() { const { ready } = useAuth();
if (!ready) { return <Stack />; }
return <GuardedStack />;}
function Providers({ children }: Readonly<{ children: React.ReactNode }>) { const theme = useThemeConfig();
return ( <GestureHandlerRootView style={styles.container} className={theme.dark ? `dark` : undefined} > <KeyboardProvider> <ThemeProvider value={theme}> <APIProvider> <AuthProvider> <AnalyticsProvider providers={analyticsProviders}> <BottomSheetModalProvider> {children} <FlashMessage position="top" /> </BottomSheetModalProvider> </AnalyticsProvider> </AuthProvider> </APIProvider> </ThemeProvider> </KeyboardProvider> </GestureHandlerRootView> );}
const styles = StyleSheet.create({ container: { flex: 1, },});The Demo app comes with a simple stack and tabs layout. Feel free to remove what is not working for you and add your own using the same approach as the existing ones.
Here is a simple example of the tabs layout.
import type { ColorValue } from 'react-native';import { Link, Redirect, SplashScreen, Tabs } from 'expo-router';import { useCallback, useEffect } from 'react';import { useTranslation } from 'react-i18next';
import { useAuth } from '@/components/providers/auth';import { Pressable, Text } from '@/components/ui';import { Feed as FeedIcon, Settings as SettingsIcon, Style as StyleIcon,} from '@/components/ui/icons';import { useIsFirstTime } from '@/lib';
type TabBarIconProps = { color: ColorValue };
function renderFeedIcon({ color }: TabBarIconProps) { return <FeedIcon color={color} />;}
function renderStyleIcon({ color }: TabBarIconProps) { return <StyleIcon color={color} />;}
function renderSettingsIcon({ color }: TabBarIconProps) { return <SettingsIcon color={color} />;}
function renderCreateNewPostLink() { return <CreateNewPostLink />;}
export default function TabLayout() { const { isAuthenticated, ready } = useAuth(); const [isFirstTime] = useIsFirstTime(); const { t } = useTranslation(); const hideSplash = useCallback(async () => { await SplashScreen.hideAsync(); }, []);
useEffect(() => { if (!ready) { void hideSplash(); } }, [hideSplash, ready]);
if (isFirstTime) { return <Redirect href="/onboarding" />; } if (!isAuthenticated && ready) { return <Redirect href="/sign-in" />; } return ( <Tabs> <Tabs.Screen name="index" options={{ title: t('tabs.feed'), tabBarIcon: renderFeedIcon, headerRight: renderCreateNewPostLink, tabBarButtonTestID: 'feed-tab', }} /> <Tabs.Screen name="style" options={{ title: t('tabs.style'), tabBarIcon: renderStyleIcon, tabBarButtonTestID: 'style-tab', }} /> <Tabs.Screen name="settings" options={{ title: t('settings.title'), tabBarIcon: renderSettingsIcon, tabBarButtonTestID: 'settings-tab', }} /> </Tabs> );}
function CreateNewPostLink() { const { t } = useTranslation();
return ( <Link href="/feed/add-post" asChild> <Pressable> <Text className="px-3 text-primary-300">{t('tabs.create')}</Text> </Pressable> </Link> );}Sitemap route
Expo Router injects a /_sitemap route that lists every route in the app, which is handy for debugging. The template removes this in-app route browser from production builds: the expo-router plugin in app.config.ts is configured with sitemap: Env.APP_ENV !== 'production'. This does not hide the route names themselves, which still ship in the JS bundle and the typed-routes output. On development, qa and staging builds you can open <scheme>://_sitemap (or /_sitemap on web); on production builds that path is handled by the template’s catch-all route, src/app/[...messing].tsx.
If you remove that catch-all route, unmatched paths fall back to Expo Router’s built-in not-found screen, which renders a hard-coded link to /_sitemap. In production that link leads nowhere, so keep a custom catch-all (or +not-found) route if you disable the sitemap.
Here is what the sitemap screen looks like (captured on the web build, development environment):

To change this behavior, update the sitemap option of the expo-router plugin in app.config.ts (set it to true to always include the route, or false to always remove it).
Because the option is read from APP_ENV when the app config is evaluated, OTA updates must also be published with APP_ENV set. env.js falls back to development when it is unset, so an eas update published to the production channel without APP_ENV=production would re-enable /_sitemap in the production app. Use the per-environment scripts, which set APP_ENV and target the matching channel:
pnpm run update:production --message "Fix login copy"update:development, update:qa and update:staging work the same way for the other channels.
Make sure to check the official docs for more information and examples about expo-router.