Building Cross-Platform Apps with React Native and Expo Router: File-Based Routing, Deep Links, and Performance Optimization

Development tutorial - IT technology blog
Development tutorial - IT technology blog

The Pain of Managing Navigation as a React Native App Grows

The early days of building a React Native app are always smooth sailing. With only 4–5 screens, everything runs effortlessly. But just three months in, the app balloons to 30–40 screens with Stacks nested inside Tabs, Modals stacked on top of Modals, and new requirements where tapping a push notification or web link has to open the exact product page. That’s when your navigation system starts falling apart.

The root problem lies in manual configuration. With vanilla React Navigation, you have to declare dozens of string-based route names, maintain scattered TypeScript types, and keep a separate mapping table for Deep Links. If a single teammate renames a screen and forgets to update that mapping table, external links break immediately. Even worse, TypeScript won’t catch it at compile time.

I once refactored a React Native codebase of over 50,000 lines, and the hardest-earned lesson was to write tests before touching legacy code. During that cleanup, the most time-consuming part was untangling a navigation tree patched together by multiple generations of developers. To avoid that trap from day one, Expo Router is the strongest option available today thanks to its File-based Routing architecture.

How File-Based Routing and Deep Links Work

File-Based Routing: Understand the Screen Flow Just by Looking at Folders

Familiar with Next.js on the web? Expo Router uses the exact same mental model. Instead of writing 200–300 lines of configuration code to wire screens together, the app/ directory structure itself serves as your app’s navigation map:

  • app/index.tsx automatically maps to the root path /.
  • app/profile.tsx corresponds to /profile.
  • app/product/[id].tsx is a dynamic route matching /product/101 or /product/ao-thun.
  • app/_layout.tsx acts as a wrapper to declare a Stack, Tabs, or Drawer for sibling screens at that level.

Just by glancing at the folder tree, new developers joining the project immediately understand how the app flows. At the same time, Expo Router automatically generates TypeScript types for all valid paths (Typed Routes), eliminating screen-name typos.

Deep Links and Universal Links: Opening the Right Screen from Outside

A Deep Link is a custom-scheme URL (such as myshop://product/42) that lets the operating system open directly to a detail screen instead of stopping at the home page. Universal Links (on iOS) and App Links (on Android) work the same way but use standard URLs like https://myshop.vn/product/42, falling back to the browser if the user hasn’t installed the app.

In the past, many teams avoided Deep Links because they had to manually sync URLs with the internal screen tree. Expo Router eliminates that step: every file inside app/ gets a matching URL path by default. For Universal Links, you only need to host the domain verification files (apple-app-site-association for iOS and assetlinks.json for Android) on your server—Expo Router handles the in-app navigation automatically.

Why Do React Native Apps Lag?

Most frame drops come down to three culprits: loading too much JavaScript at startup, re-rendering an entire long list whenever state changes, and decoding high-resolution images without caching. To hold a steady 60 FPS (keeping each frame under 16.6 ms), we need to enable the Hermes engine, use lazy loading (lazy) for unopened tabs, and optimize both list rendering and image memory.

Hands-On: Building and Optimizing an App with React Native & Expo Router

Step 1: Initialize an Expo Router Project

Open your terminal and create a new project using the default template, which comes pre-configured with Expo Router and TypeScript:

npx create-expo-app@latest my-shop-app --template tabs
cd my-shop-app
npx expo start

Inside the newly created project, the app/ folder already includes _layout.tsx and a (tabs)/ directory. The parentheses in (tabs) denote a Route Group: it groups screens that share a bottom tab bar without inserting the word tabs into the URL.

Step 2: Configure the Stack and Dynamic Route

Open app/_layout.tsx to declare the root Stack, enabling smooth transitions from the Tab group to the product detail screen:

import { Stack } from 'expo-router';

export default function RootLayout() {
  return (
    <Stack>
      <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
      <Stack.Screen name="product/[id]" options={{ title: 'Product Details' }} />
    </Stack>
  );
}

Next, create app/product/[id].tsx and use the useLocalSearchParams hook to read the dynamic id parameter from the URL:

import { View, Text, StyleSheet } from 'react-native';
import { useLocalSearchParams, Link } from 'expo-router';

export default function ProductDetailScreen() {
  const { id } = useLocalSearchParams<{ id: string }>();

  return (
    <View style={styles.container}>
      <Text style={styles.title}>Product ID: {id}</Text>
      <Link href="/" style={styles.link}>
        Back to Home
      </Link>
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: 16 },
  title: { fontSize: 18, fontWeight: '600', marginBottom: 12 },
  link: { color: '#007AFF', fontSize: 16 },
});

Step 3: Declare the Scheme in app.json and Test Deep Links

So Android and iOS can recognize your app’s custom URLs, open app.json and add the scheme field:

{
  "expo": {
    "name": "My Shop App",
    "slug": "my-shop-app",
    "scheme": "myshop"
  }
}

Without needing a complex native rebuild, you can test the Deep Link flow right away on your simulator or emulator with these two commands:

# Test on Android Emulator
npx uri-scheme open "myshop://product/42" --android

# Test on iOS Simulator
npx uri-scheme open "myshop://product/42" --ios

Once the app launches automatically and displays Product ID: 42, you’re all set. The entire setup takes just a few lines.

Step 4: Optimize Performance for Lists of Hundreds of Products

When a product list grows to 500–1,000 items with thumbnails, naive rendering will cause noticeable FPS drops. These three techniques keep scrolling silky smooth even on mid-range Android devices:

  1. Use expo-image instead of the default Image component: expo-image caches images smartly in both RAM and disk and decodes them asynchronously, drastically reducing stutter during fast scrolling.
  2. Tune FlatList props or switch to FlashList: Always pass keyExtractor, limit initialNumToRender={10}, and set windowSize={5} to reduce the number of views kept in memory. If your list exceeds 1,000 complex items, switch to @shopify/flash-list for more efficient cell recycling.
  3. Prevent unnecessary re-renders with React.memo and useCallback: Wrap each item in React.memo so that when the cart count updates, hundreds of other product rows aren’t needlessly re-rendered.
import React, { useCallback } from 'react';
import { FlatList, Pressable, Text } from 'react-native';
import { Image } from 'expo-image';
import { router } from 'expo-router';

type Product = { id: string; name: string; thumb: string };

const ProductItem = React.memo(({ item }: { item: Product }) => {
  const handlePress = useCallback(() => {
    router.push(`/product/${item.id}`);
  }, [item.id]);

  return (
    <Pressable onPress={handlePress} style={{ flexDirection: 'row', padding: 12 }}>
      <Image
        source={{ uri: item.thumb }}
        style={{ width: 64, height: 64, borderRadius: 8 }}
        contentFit="cover"
        cachePolicy="memory-disk"
      />
      <Text style={{ marginLeft: 12, fontSize: 16 }}>{item.name}</Text>
    </Pressable>
  );
});

export function ProductList({ data }: { data: Product[] }) {
  return (
    <FlatList
      data={data}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => <ProductItem item={item} />}
      initialNumToRender={10}
      maxToRenderPerBatch={10}
      windowSize={5}
    />
  );
}

Conclusion

Using Expo Router lets you eliminate hundreds of lines of manual navigation boilerplate, keeps Deep Links automatically synced with your directory structure, and keeps your codebase clean as your team scales. Combined with expo-image, React.memo, and a properly tuned FlatList, your cross-platform app can easily deliver fast, fluid responsiveness.

About to kick off a new project or planning to migrate off legacy React Navigation? Try spinning up a small branch with Expo Router, write a few test cases for your core screen transitions, and then gradually migrate the rest of the app.

Share: