Product pages, order receipts and help articles share one layout from item to item, and only the identifier in the URL changes. Expo Router lets a single file answer all of those URLs by turning part of the path into a value the screen receives. Linking to those screens needs some care too, because an href has to name its full destination.
Key terms
- Dynamic route: a route whose file or folder name is wrapped in square brackets, such as
[sku].tsx, so that segment of the URL becomes a parameter. - Catch-all route: a dynamic route written with rest syntax, such as
[...topic].tsx, which captures one or more segments. - Route parameter: the value a dynamic segment takes from the URL, like
blue-mugin/products/blue-mug. - HrefObject: the object form of an href, with a
pathnameand optionalparams.
Square brackets in a file name
src/app/products/[sku].tsx is a dynamic route. It matches /products/blue-mug, /products/oak-desk and any other single value in that position, and the screen receives that value as the sku route parameter. Screens read it with the useLocalSearchParams hook.
The brackets can go on a folder instead of a file: src/app/products/[sku]/index.tsx is a dynamic route too. Either way, the name inside the brackets becomes the parameter's key, and a plain bracketed name captures exactly one segment.
Catch-all routes with three dots
Put three dots before the name and the parameter captures one or more segments. A help center with nested topics fits in one file, src/app/help/[...topic].tsx, which matches /help/shipping as well as /help/shipping/returns/abroad.
A catch-all parameter arrives as an array of strings, one item per segment. It stays an array when only one segment matched:
tsx// URL /help/shipping gives { topic: ['shipping'] } // URL /help/shipping/returns gives { topic: ['shipping', 'returns'] }
Code that reads it indexes into the array or joins it, as in topic.join(' / ') for a breadcrumb.
Two ways to link to a dynamic route
An href to a dynamic route is either its full URL as a string or an HrefObject. In the object, pathname is the file's path with the brackets left in, and params supplies the values. Both forms work with Link and with router.push. The ShopHome screen below links to one product three ways, then to a help article and an order.
The first two links are strings, and the template literal in the second is ordinary TypeScript. The third passes { pathname: '/products/[sku]', params: { sku, color: 'navy' } }. When Expo Router resolves an HrefObject, each param whose name matches a bracketed segment is URL-encoded into the path and removed from params. Whatever is left becomes the query string, so this link opens /products/blue-mug?color=navy. Each value goes through toString(), and null or undefined values are dropped.
The help link shows the catch-all case: the topic array is encoded item by item and joined with /, which gives /help/shipping/returns.
Keep params flat. Expo Router URL params must be serializable as strings, and nested object params aren't supported. Since each value goes through toString(), an object would reach the URL as the text [object Object].
Complete hrefs for nested screens
screen, params and initial are ordinary params like any other key, so an href must name the destination screen itself. An href that points at a navigator and names the screen in its params doesn't reach that screen:
tsx// screen is an ordinary param here, so this opens the (tabs) index with ?screen=orders router.push({ pathname: '/(tabs)', params: { screen: 'orders' } }); // a complete href names the destination itself router.push('/(tabs)/orders');
Write the whole path to the screen instead, dynamic segments included, as the router.push call to /(tabs)/orders/[id] in ShopHome does. Route group segments are optional when a path is matched, so /orders/1042 and /(tabs)/orders/1042 reach the same route, and a complete href may include the group.
Navigating with the router's methods doesn't copy a parent route's params into the screen it opens. If a screen needs a value from its parent route, include that value in the destination href.
Code Examples
import { Link, useRouter } from 'expo-router';
import { Pressable, Text, View } from 'react-native';
export default function ShopHome() {
const router = useRouter();
const sku = 'blue-mug';
return (
<View>
<Link href="/products/blue-mug">Blue mug</Link>
<Link href={`/products/${sku}`}>Blue mug again</Link>
<Link href={{ pathname: '/products/[sku]', params: { sku, color: 'navy' } }}>
Blue mug in navy
</Link>
<Link href={{ pathname: '/help/[...topic]', params: { topic: ['shipping', 'returns'] } }}>
Returns policy
</Link>
<Pressable
onPress={() => router.push({ pathname: '/(tabs)/orders/[id]', params: { id: '1042' } })}>
<Text>Latest order</Text>
</Pressable>
</View>
);
}