can take users directly to the part of an Expo app they need. This guide focuses on using
query parameters
to pass data when opening a particular screen.
Have you ever tapped a link and landed on a specific screen in an app instead of opening a web page? That is a deep link. It directs users from outside the app, such as another app, a website, or a push notification, to content or a feature inside it.
We'll use Expo Router to set up deep linking, attach query parameters to a URL, and read them from the destination screen.
A deep link gives an app screen or feature an address, much like a URL on the web, so users can reach it from outside the app. Without a deep link, a user might land on the app's home screen or in the app store, then have to open the app and navigate to the desired screen manually.
Choose a URL scheme that uniquely identifies your app. For example, if the app is called My Awesome App, you might use myawesomeapp. Set it in app.json or app.config.js.
The scheme appears at the start of a deep link, as in myawesomeapp://.... Pick a name related to the app that is unlikely to collide with a scheme used by another app.
When you build the project with the Expo CLI, the scheme is added to the native configuration in iOS's Info.plist and Android's AndroidManifest.xml.
Expo Router maps files in the app directory to URL paths. For example, app/products/detail.tsx maps to myawesomeapp://products/detail. Add query parameters after that path. They don't require a separate file.
Use deep links in places such as push notifications, websites, and marketing emails. Add ? after the scheme and path, then join the key=value pairs with &.
Open the detail page for product ID 456: myawesomeapp://products/detail?productId=456.
Open Alice's profile: myawesomeapp://users/profile?username=alice.
Search for โreact nativeโ on the results page: myawesomeapp://search?query=react%20native. URL encoding can represent the space as %20.
When a user taps one of these URLs, Expo routes to the appropriate screen and passes the query parameters to its component.
Read Deep Link Parameters with useLocalSearchParams ๐
Expo Router provides the useLocalSearchParams hook to read the query parameters on the destination screen. This example retrieves productId in app/products/detail.tsx.
Calling useLocalSearchParams returns an object containing the query parameters for the current route.
Use parameter names such as productId and category as keys on the returned object, params.
In TypeScript, specify parameter types and optionality (?) with a generic such as useLocalSearchParams<{ productId?: string; category?: string }>(). A single query parameter value comes through as a string. Convert it with a function such as parseInt() if you need a number.
Use the extracted value (productId) to display data or request details for that ID from the server.
Deep links take users straight to the content they want. Query parameters carry the information the destination screen needs, reducing the steps users have to take and making it easier to engage with the app.
Use Expo Router's useLocalSearchParams hook to retrieve those values in the destination component.