Skip to main content

Navigation and Passing Data Between Screens in React Native

Your goal: Select a book, open its details, and return to the Reading List with its reading progress intact.

Before you begin: Complete React Hooks and Managing State and restore its complete Reading List if you tried the timer experiment. Use the same Expo Router project from Development Environment.

By the end, you will be able to:

  • Explain screens, routes, stack history, and back navigation.
  • Connect route files with a minimal Expo Router layout.
  • Pass a stable book ID and validate it on the receiving screen.
  • Keep navigation separate from read/unread updates and explain where state lives.

Understand screens and navigation​

Navigation moves someone between views of an application. A screen is the interface they see; a route identifies which screen to show and can include parameters selecting its content. Our Reading List is the / route. /books/hobbit opens Book Details for The Hobbit.

The reader’s journey
Reading List
↓ select a book (push)
Book Details
↓ back
Reading List (the existing screen)

A stack remembers screens in order, like a pile of cards. Pushing Details puts it above Reading List. Going back removes, or pops, Details and reveals the previous screen. Back follows navigation history; it does not mean “always open the home page.” Opening a details URL directly may provide no previous in-app screen, so we will also provide a way to reach Reading List from that situation.

Use the router already in your project​

We use Expo Router because the earlier Expo project already includes it. Its file-based routes map screen files to paths, support stacks and dynamic segments, and work on iOS, Android, and web. See the Expo Router introduction.

It is not the only navigation option. React Navigation lets you configure navigators and screens explicitly. You do not need a second implementation or extra navigation packages for this lesson.

Route parameters are not ordinary props​

A component prop such as onToggleRead passes a value directly from a parent to its child. A route parameter is part of a navigation address. Here id selects the book to show. It can arrive from a URL someone typed or shared, without the Reading List ever rendering.

Ordinary component propRoute parameter
BookCard receives title, isRead, and callbacks from HomeScreen.Book Details reads id from its route.
Can carry a function or an in-memory object.Use simple URL values, such as a stable string ID.
Updates when the parent supplies a new value.Identifies route content; it does not synchronize editable state.

Pass hobbit, not the entire book object. An ID survives title changes and lets the destination look up the shared definition. Complex objects and callbacks do not belong in URL parameters; even book data converted to text could become stale.

Arrange the files​

What changes in this lesson: The Hooks screen becomes a two-screen app. Move its book definitions and card into separate files, update src/app/index.tsx and the root layout, and add src/app/books/[id].tsx. Selecting a title opens Details; the separate read/unread button still updates the list. These five files belong in your learning app.

Reading List source files
src/
app/
_layout.tsx
index.tsx
books/
[id].tsx
data/
books.ts
components/
BookCard.tsx
FileResponsibility
src/app/_layout.tsxArrange routes in a stack and set header titles.
src/app/index.tsxRender Reading List at / and own editable read status.
src/app/books/[id].tsxRender Book Details for a dynamic ID.
src/data/books.tsExport the original book type and starting definitions.
src/components/BookCard.tsxDisplay a card with two separate actions.

Shared data and components stay outside app so Router does not treat them as screens. The brackets in [id].tsx are literal filename characters: one file serves /books/hobbit, /books/earthsea, and other IDs.

If an older template used app/(tabs)/index.tsx, first save your work, move the learning screen into this structure, and remove the old template routes/layouts that conflict with it. Use one route root, src/app, rather than keeping both app and src/app. The five files below replace the lesson’s screen/layout code; retain the Expo project configuration and installed dependencies. This assumes the working Expo Router and react-native-safe-area-context setup from earlier lessons, with no new installation.

Try the navigation calls​

These small fragments explain the API; the complete files below include their required imports and surrounding components.

Inside HomeScreen
const router = useRouter();

// In a book’s press handler:
router.push({
pathname: '/books/[id]',
params: { id: book.id },
});

router.push adds a screen to history. pathname names the route pattern, and params fills its dynamic id segment. For The Hobbit, the resulting path is /books/hobbit. Our complete list uses item.id because FlatList calls the current book item.

For a declarative alternative, import Link from expo-router and render this in a component with a book value:

Alternative only — not added to the complete app
<Link push href={{ pathname: '/books/[id]', params: { id: book.id } }}>
View details
</Link>

Link declares a destination in JSX; push requests a new stack entry. We use press handlers throughout the main example. See Expo’s navigation guide.

Keep one owner for reading status​

The Hooks lesson’s Book type and initialBooks move to a shared file unchanged. HomeScreen still initializes its editable books state from them and replaces objects immutably when toggling. That never changes the exported starting definitions.

Details looks up stable title and author information in initialBooks. It deliberately does not display or edit isRead: that field in the shared file is only an initial value, not current progress. Importing the same array in two screens does not share React state.

Pushing Details keeps the existing Home screen mounted in this stack. Back reveals its current progress. A full reload, app restart, or removal/remounting of Home resets local state. Navigation is not permanent storage. If both screens later need live status, they will need a common state owner above both routes, as the next Networking lesson demonstrates with Context. Saving across restarts comes later in Local Data Persistence.

Run the complete application​

Copy all five files into the learning app. They contain every helper and style needed for this example.

1. Share the starting books​

src/data/books.ts
export type Book = {
id: string;
title: string;
author: string;
isRead: boolean;
};

export const initialBooks: Book[] = [
{ id: 'hobbit', title: 'The Hobbit', author: 'J. R. R. Tolkien', isRead: false },
{ id: 'earthsea', title: 'A Wizard of Earthsea', author: 'Ursula K. Le Guin', isRead: false },
{ id: 'secret-garden', title: 'The Secret Garden', author: 'Frances Hodgson Burnett', isRead: false },
];

2. Configure the stack​

_layout.tsx wraps the routes with navigation structure. Stack discovers screen files; Stack.Screen supplies options rather than importing the components manually. Names match route paths without extensions. The default header shows the configured title and a back control when a previous stack entry exists. Keep that native header and Android’s normal back behavior.

src/app/_layout.tsx
import { Stack } from 'expo-router';

export default function RootLayout() {
return (
<Stack>
<Stack.Screen name="index" options={{ title: 'Reading List' }} />
<Stack.Screen name="books/[id]" options={{ title: 'Book Details' }} />
</Stack>
);
}

The header handles the top safe area. Both screens use SafeAreaView for the left, right, and bottom edges to avoid adding the top inset twice. Expo Router provides the surrounding safe-area support. See navigation layouts.

3. Give each card separate actions​

The title/author area opens Details; the status button only toggles reading progress. These Pressable controls are siblings inside a plain View, never nested. Both have action-and-book accessibility labels, press feedback, and a minimum touch height. The decorative emoji remains hidden from screen readers.

src/components/BookCard.tsx
import { Pressable, StyleSheet, Text, View } from 'react-native';

type BookCardProps = {
title: string;
author: string;
isRead: boolean;
onToggleRead: () => void;
onOpenDetails: () => void;
};

export default function BookCard({ title, author, isRead, onToggleRead, onOpenDetails }: BookCardProps) {
const buttonLabel = isRead ? 'Mark as unread' : 'Mark as read';

return (
<View style={styles.card}>
<Pressable
style={({ pressed }) => [styles.bookRow, pressed && styles.detailsPressed]}
onPress={onOpenDetails}
accessibilityRole="button"
accessibilityLabel={'View details: ' + title}
>
<Text
style={styles.bookIcon}
accessible={false}
accessibilityElementsHidden={true}
importantForAccessibility="no"
>
📖
</Text>
<View style={styles.details}>
<Text style={styles.bookTitle}>{title}</Text>
<Text style={styles.author}>{author}</Text>
<Text style={styles.detailsLink}>View details →</Text>
</View>
</Pressable>
<Text style={[styles.status, isRead && styles.readStatus]}>
Status: {isRead ? 'Read' : 'Unread'}
</Text>
<Pressable
style={({ pressed }) => [styles.button, pressed && styles.buttonPressed]}
onPress={onToggleRead}
accessibilityRole="button"
accessibilityLabel={buttonLabel + ': ' + title}
>
<Text style={styles.buttonText}>{buttonLabel}</Text>
</Pressable>
</View>
);
}

const styles = StyleSheet.create({
card: {
padding: 16,
gap: 12,
backgroundColor: '#ffffff',
borderWidth: 1,
borderColor: '#cbd5e1',
borderRadius: 16,
},
detailsPressed: { opacity: 0.7 },
detailsLink: { color: '#1e40af', fontSize: 16, fontWeight: '600' },
bookRow: { minHeight: 48, flexDirection: 'row', alignItems: 'flex-start', gap: 12 },
bookIcon: { fontSize: 28, flexShrink: 0 },
details: { flex: 1, gap: 4 },
bookTitle: { color: '#0f172a', fontSize: 20, fontWeight: '600' },
author: { color: '#475569', fontSize: 16 },
status: {
alignSelf: 'flex-start',
maxWidth: '100%',
paddingHorizontal: 10,
paddingVertical: 6,
borderRadius: 8,
backgroundColor: '#e2e8f0',
color: '#334155',
fontSize: 14,
fontWeight: '600',
},
readStatus: { backgroundColor: '#dcfce7', color: '#166534' },
button: {
minHeight: 48,
padding: 12,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1e40af',
borderRadius: 10,
},
buttonPressed: { backgroundColor: '#1e3a8a' },
buttonText: { color: '#ffffff', fontSize: 16, fontWeight: '600', textAlign: 'center' },
});

4. Connect the Reading List​

The state updater, FlatList, empty state, and derived progress remain familiar. onOpenDetails is a new ordinary callback prop: the parent closes over the selected ID and calls the router when the card asks to open it.

src/app/index.tsx
import { useState } from 'react';
import { useRouter } from 'expo-router';
import { FlatList, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import BookCard from '../components/BookCard';
import { initialBooks } from '../data/books';
import type { Book } from '../data/books';

export default function HomeScreen() {
const router = useRouter();
const [books, setBooks] = useState<Book[]>(initialBooks);
const completedCount = books.filter(book => book.isRead).length;
const progressPercent = books.length === 0
? 0
: (completedCount / books.length) * 100;

function toggleRead(selectedId: string) {
setBooks(previous =>
previous.map(book =>
book.id === selectedId
? { ...book, isRead: !book.isRead }
: book
)
);
}

return (
<SafeAreaView style={styles.screen} edges={['left', 'right', 'bottom']}>
<FlatList
data={books}
keyExtractor={book => book.id}
renderItem={({ item }) => (
<BookCard
title={item.title}
author={item.author}
isRead={item.isRead}
onToggleRead={() => toggleRead(item.id)}
onOpenDetails={() => router.push({
pathname: '/books/[id]',
params: { id: item.id },
})}
/>
)}
contentContainerStyle={styles.content}
ListHeaderComponent={
<View style={styles.header}>
<Text style={styles.heading} accessibilityRole="header">
My Reading List
</Text>
<Text style={styles.subtitle}>Find your next good read</Text>
<Text style={styles.summary}>
{completedCount} of {books.length} books read
</Text>
<View
style={styles.progressTrack}
accessible={true}
accessibilityRole="progressbar"
accessibilityLabel="Reading progress"
accessibilityValue={{
min: 0,
max: 100,
now: Math.round(progressPercent),
text: `${completedCount} of ${books.length} books read`,
}}
>
<View
style={[styles.progressFill, { width: `${progressPercent}%` }]}
/>
</View>
</View>
}
ItemSeparatorComponent={() => <View style={styles.separator} />}
ListEmptyComponent={
<View style={styles.card}>
<Text style={styles.bookTitle}>Your reading list is empty</Text>
<Text style={styles.author}>
Add a book to the initialBooks array to start your list.
</Text>
</View>
}
/>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#f1f5f9' },
content: { padding: 16 },
separator: { height: 16 },
header: { gap: 6, marginBottom: 20 },
heading: { color: '#0f172a', fontSize: 28, fontWeight: '700' },
subtitle: { color: '#475569', fontSize: 16 },
summary: { color: '#334155', fontSize: 16, fontWeight: '600' },
progressTrack: {
height: 12,
borderRadius: 6,
backgroundColor: '#cbd5e1',
overflow: 'hidden',
},
progressFill: { height: '100%', backgroundColor: '#1e40af' },
card: {
padding: 16,
gap: 12,
backgroundColor: '#ffffff',
borderWidth: 1,
borderColor: '#cbd5e1',
borderRadius: 16,
},
bookTitle: { color: '#0f172a', fontSize: 20, fontWeight: '600' },
author: { color: '#475569', fontSize: 16 },
});

5. Read the ID and show Details​

useLocalSearchParams reads parameters for this route, including the dynamic id. The type permits a missing value or an array so we handle unexpected input explicitly. The TypeScript annotation does not validate incoming URLs. A single string must also match a known book; find returns undefined otherwise. Missing, array-shaped, empty, and unknown IDs all reach the friendly fallback.

src/app/books/[id].tsx
import { useLocalSearchParams, useRouter } from 'expo-router';
import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { initialBooks } from '../../data/books';

export default function BookDetailsScreen() {
const { id } = useLocalSearchParams<{ id?: string | string[] }>();
const router = useRouter();
const book = typeof id === 'string'
? initialBooks.find(candidate => candidate.id === id)
: undefined;

function returnToReadingList() {
// In this two-screen app, a previous in-app screen is Reading List.
if (router.canGoBack()) {
router.back();
} else {
router.replace('/');
}
}

return (
<SafeAreaView style={styles.screen} edges={['left', 'right', 'bottom']}>
<ScrollView contentContainerStyle={styles.content}>
<View style={styles.card}>
{book ? (
<>
<Text style={styles.heading} accessibilityRole="header">
{book.title}
</Text>
<Text style={styles.author}>{book.author}</Text>
<Text style={styles.body}>
Return to your Reading List to mark this book as read or unread.
</Text>
</>
) : (
<>
<Text style={styles.heading} accessibilityRole="header">
Book not found
</Text>
<Text style={styles.body}>
We could not find that book. Choose one from your Reading List.
</Text>
</>
)}
<Pressable
style={({ pressed }) => [styles.button, pressed && styles.buttonPressed]}
onPress={returnToReadingList}
accessibilityRole="button"
accessibilityLabel="Return to Reading List"
>
<Text style={styles.buttonText}>Return to Reading List</Text>
</Pressable>
</View>
</ScrollView>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
screen: { flex: 1, backgroundColor: '#f1f5f9' },
content: { padding: 16 },
card: {
padding: 16,
gap: 12,
backgroundColor: '#ffffff',
borderWidth: 1,
borderColor: '#cbd5e1',
borderRadius: 16,
},
heading: { color: '#0f172a', fontSize: 28, fontWeight: '700' },
author: { color: '#475569', fontSize: 20 },
body: { color: '#334155', fontSize: 16 },
button: {
minHeight: 48,
padding: 12,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1e40af',
borderRadius: 10,
},
buttonPressed: { backgroundColor: '#1e3a8a' },
buttonText: { color: '#ffffff', fontSize: 16, fontWeight: '600', textAlign: 'center' },
});

Despite its name, useLocalSearchParams reads dynamic route segments as well as query parameters. Use the local hook to read this screen’s own book ID. See Expo’s URL parameter reference.

The header back button handles the normal list-to-details journey. The additional return control also works when Details is opened directly: canGoBack() checks for history, and replace('/') replaces the current entry when there is none. It does not push another Reading List over the old one. This helper assumes our two-screen flow; in a larger app, the previous screen might be somewhere else.

Check the expected behavior​

Run npx expo start from the learning app. Open it on your phone, or press w for the web preview.

  1. Confirm the three original books and 0 of 3 books read appear. Mark The Hobbit as read: the summary becomes 1 of 3, with the same status styling and progress bar.
  2. Select The Hobbit’s title area. Details shows The Hobbit and J. R. R. Tolkien, with the Book Details header. Opening it must not toggle status.
  3. Use the header back control (or Android back). The existing list still shows 1 of 3. Open the other books and verify their authors. The toggle button must not navigate.
  4. In the web preview, enter /books/unknown after the local server’s origin. Expect Book not found. Select Return to Reading List. Also open /books/hobbit in a fresh tab to check the direct-entry return path.
  5. Fully reload the app: status starts unread again. On a narrow screen and with larger device text, scroll to every action. With a screen reader, check that the two card actions have distinct labels.

An unknown ID such as /books/unknown matches our dynamic route and receives our fallback. A missing path segment such as /books does not match [id].tsx; Router handles it as an unmatched route. There is no separate custom unmatched-route screen in this lesson.

Fix common mistakes​

If you see…Check this
A route cannot be foundUse the literal filename books/[id].tsx, a default component export, and pathname /books/[id]. Match params.id to [id].
The intended stack or header is absentInclude the root _layout.tsx; remove conflicting template layouts and do not hide the header.
A book lookup crashes or shows nothingValidate the parameter shape and handle find returning undefined.
You want to pass an entire book or callbackPass its stable ID. URL parameters are not an in-memory data transport.
Details expects BookCard propsRouter renders the route. Read its parameters with the hook, then look up the book.
Progress resets after reload or remountLocal state lasts only as long as its owner remains mounted. Back in this stack preserves Home; restarting does not.
Two screens disagree about statusDo not create two editable collections. Shared definitions are not shared mutable state.
Selecting status also opens DetailsKeep the two press targets separate; do not wrap the whole card in another Pressable.

Practice​

  1. Add a fourth book. Give it a unique ID in initialBooks, reload, and open its details. Check that the progress denominator also changes.
  2. Add a category. Extend the shared Book type and definitions with a static category, then display it on Details. Keep reading status owned by Home.
  3. Change the header title. Change the Details title in the root layout and check the header and back behavior on your device.

Check your understanding​

  1. What is on the stack after you select a book, and what does Back remove?
  2. Why is an ID a better route parameter than a book object or toggle callback?
  3. What should happen if the route contains an unknown ID?
  4. Does importing initialBooks in Details give it the current read status?
Compare your answers

Reading List is beneath Details; Back removes Details and reveals the existing list. A stable ID identifies content through a URL without copying mutable data or trying to serialize functions. An unknown ID shows a helpful fallback with a return action. The imported definitions contain starting values only; current status lives in Home’s state. Sharing live status would require an owner accessible to both screens.

You are ready to continue when: You can open each book, return without losing progress during the normal stack journey, and explain why a reload resets it.

Return to the learning path for further resources. Shared mutable state across routes, persistent storage, API data, and advanced navigators are intentionally outside this lesson.

Official references​