Screens and navigation
You'll learn how Expo Router turns files into screens, and how a stack opens a screen and goes back.
Watch & read
Start with the required ones. The others are there when you need them.
See it step by step
A stack of screens. Push puts one on top, back takes the top one off.
Explanation
So far your app has one screen. Now you want to tap "Drink water" and open a screen just for that habit,
with a Back arrow to return. Expo Router does this with files: every file in the src/app folder is a
screen. (Older projects and many videos keep it in app/ at the top; it works the same way.)
src/app/_layout.jsx the frame around every screensrc/app/index.jsx "/" the home screensrc/app/add.jsx "/add"src/app/habit/[id].jsx "/habit/h1", "/habit/h2", ...
The address of a screen is called a route. index.jsx is /. A name in square brackets, like
[id], is a blank to fill in, so one file works for every habit.
_layout.jsx decides how screens are arranged. return <Stack /> makes a stack. Think of a pile
of exam papers on the teacher's desk. A new screen is put on top (push). Back takes the top one off
(pop), and you see the one underneath again. The Stack gives every screen a header with a Back arrow
for free.
<Link href="/habit/h1">Drink water</Link>const router = useRouter();<Pressable onPress={() => router.push("/add")}><Text>Add a habit</Text></Pressable>
Linkis tappable text that opens a route, like<a href>on the web.router.push("/add")does the same from your own code, for example after a check.router.back()closes the top screen. You'll also seerouter.navigate, which goes back to a screen if it is already in the pile instead of adding a copy.- On the habit screen,
useLocalSearchParams()reads the blank:const { id } = useLocalSearchParams();gives"h1".
People often forget that the folder decides the route. router.push("/habits/h1") when the folder is
habit opens Expo Router's "page not found" screen. Check the path against the file names. Another one:
Link wraps its children in Text. To make a whole card tappable, use <Link href="..." asChild> with a
Pressable inside.
When you read an Expo Router project, start with the file list in src/app, then open each _layout.jsx
to see which screens are in a Stack. Then every Link and router.push is just "put this route on top".
Code tour
Click a line number with a ring to read the note for that line.
Practice
Short drills. Take your time and read the code before you answer.
1// src/app/index.jsx (Home)2<Pressable onPress={() => router.push("/habit/h1")}>3 <Text>Drink water</Text>4</Pressable>56// src/app/habit/[id].jsx (Habit)7<Pressable onPress={() => router.push("/edit/h1")}>8 <Text>Edit</Text>9</Pressable>1011// src/app/edit/[id].jsx (Edit)12<Pressable onPress={() => router.back()}>13 <Text>Save</Text>14</Pressable>1516// The app opens on Home. You tap "Drink water", then "Edit", then "Save".
1import { NavigationContainer } from "@react-navigation/native";2import { createNativeStackNavigator } from "@react-navigation/native-stack";3import { Pressable, StyleSheet, Text, View } from "react-native";45const Stack = createNativeStackNavigator();6const habits = [
Runs in the browser. Choose “My Device” in Snack to try it on your phone with Expo Go.
navigation.goBack(). Add navigation next to route in HabitScreen's props.Quick check
3 questions. Each one explains itself after you answer.
- 1 / 3
- 2 / 3
- 3 / 3
Explain it back
How confident are you with Screens and navigation?
Done
src/app folder and its Link and router.push calls, and say which screen opens and where Back goes.