Receiving links
Listen with Lander.onDeepLink or useLanderDeepLink, understand cold start, warm start and deferred delivery, and route with React Navigation or Expo Router.
Every link that opens your app reaches you as a LanderLink, through one listener: Lander.onDeepLink (or the useLanderDeepLink hook). You listen once, at the root of your app, and send each link to your navigator.
The LanderLink
A LanderLink is a frozen plain object. Every field, route and isResolved included, is a data property, so a link can be passed as a React Navigation param or serialized as JSON.
| Field | Type | Meaning |
|---|---|---|
route | string | Where to navigate: the link's path when resolved, otherwise the raw URL's path and query. |
url | string | The URL that opened the app, exactly as the OS delivered it. |
isResolved | boolean | Whether Lander recognized the link (linkId !== null). |
linkId | string | null | Lander link ID (a UUID). Pass it to trackEvent to attribute conversions. |
shortUrl | string | null | Canonical short link, for example https://acme.golander.link/p-123. |
path | string | null | The in app route set on the link, for example /product/123. |
params | Record<string, string | number | boolean> | Link params with the opened URL's query parameters merged over them. |
campaign, channel | string | null | Attribution labels set on the link. |
isDeferred | boolean | True when the link was recovered after an install or handed off after sign in. |
confidence | LanderConfidence | 'deterministic', 'probabilistic' or 'unattributed'. |
method | string | null | How the link was tied to the open: universal_link, app_link, install_referrer, landing_page, authenticated_handoff or probabilistic_match. |
Full details are in the API reference.
Listen for links
With the hook, in a component that stays mounted (your root):
import { useLanderDeepLink } from 'react-native-lander'
useLanderDeepLink((link) => {
openRoute(link.route, link)
})Or without React, for example next to your navigator setup:
import { Lander } from 'react-native-lander'
const subscription = Lander.onDeepLink((link) => openRoute(link.route, link))
// Later, if you ever need to stop:
subscription.remove()useLanderDeepLink subscribes in an effect, unsubscribes on unmount and always calls the latest function you pass, so you do not need useCallback. Complete examples for React Navigation and Expo Router are below.
Cold start, warm start and deferred
A link can reach your app in three situations. All three arrive through the same listener.
| Situation | What happened | How the SDK gets it | Typical method |
|---|---|---|---|
| Cold start | The app was not running. The tap launched it. | iOS: Linking.getInitialURL(). Android: the launch intent, read by the SDK's native module. | universal_link or app_link |
| Warm start | The app was running or in the background. | iOS: Linking url events. Android: onNewIntent, read by the native module. | universal_link or app_link |
| Deferred | The app was not installed. The person installed it from the store and opened it for the first time. | No URL at all: Lander returns the link in its answer to the first launch report (POST /v1/sdk/init). | install_referrer or probabilistic_match |
Cold start and deferred links are both "the link that launched the app", so they are delivered once, either to your listener or through getInitialLink(). Warm start links always go to the listener.
If the app was opened by a link on its very first launch, that link wins and no deferred link is delivered on top of it.
The iOS Continue in app page sits in between: after installing, the person taps "open it" on the page, so the link arrives as an ordinary cold start open, but with method: 'landing_page' and isDeferred: true when the app was installed after the click.
Confidence levels
Every link carries a confidence, so you can decide how much to trust it:
confidence | When | What to do with it |
|---|---|---|
'deterministic' | A tap on a Universal Link or App Link, an Android install referrer token, the iOS Continue in app page or an authenticated handoff. Lander knows. | Treat it as if the user tapped it in your app. |
'probabilistic' | Opt in iOS probabilistic matching guessed the link from coarse signals. Usually right, sometimes wrong. | Show the screen, but never sign someone in, apply a credit or reveal anything private because of it. |
'unattributed' | Lander could not tie a link to this open. Unresolved links always have this. | Route on the raw URL if you want; there is no Lander data. |
More on how each one is decided in Attribution and Deferred links.
Buffered, exactly once delivery
You never have to race the SDK at startup:
- Buffered. Links that arrive while nothing listens are kept and replayed, in order, to the next listener. This covers cold starts and links that arrive before your navigator is ready. You can even subscribe before
initialize. - Never during the subscribe call. Buffered links are replayed right after
onDeepLinkreturns (in a microtask), so your listener never runs inside your own effect. - The launch link is delivered once. It goes to the listener unless
getInitialLink()claims it first. Whichever gets it first wins, so navigation never happens twice. - In arrival order. Links are resolved one after another, so they come out in the order they were tapped.
- Duplicates are dropped. The same URL reported twice within two seconds counts as one open (iOS can report a launch URL through more than one callback).
- Recents is not a new open. On Android, reopening the app from Recents, or Android recreating the activity after killing the app in the background, replays the original launch intent; the SDK ignores it.
- Opens are reported for you. Lander records the open when the SDK resolves the link. You do not need to track opens yourself.
Every active listener gets live links. Buffered links go to the first listener that subscribes, so keep a single listener at the root of your app. If you remove it and subscribe again later, links that arrived in between are buffered and replayed. React's Strict Mode, which mounts effects twice in development, is fine: the buffer is replayed to the subscription that stays.
Turn off other deep link handling
Lander delivers every link to your listener, including custom scheme URLs. If your navigation library also opens incoming URLs on its own, each link navigates twice.
-
React Navigation: do not pass a
linkingprop toNavigationContainerfor URLs Lander handles. If you needlinkingfor something else, leave your Lander domains and scheme out ofprefixes, or exclude them withfilter:const linking = { prefixes: ['https://www.acme.com'], // Lander delivers these through onDeepLink. filter: (url: string) => !/^(https:\/\/acme\.golander\.link|acmeshop:)/.test(url), } -
Expo Router: it opens every incoming URL itself. Add a
+native-intent.tsxfile, shown below, so it ignores Lander's.
getInitialLink: pick the first screen
Most apps only need the listener. Use getInitialLink() when you want to choose the first screen from the launch link, for example behind a splash screen:
const [initialRoute, setInitialRoute] = useState<string | null>(null)
useEffect(() => {
Lander.getInitialLink()
.then((link) => setInitialRoute(link?.route ?? '/')) // waits for the network, see below
.catch(() => setInitialRoute('/'))
}, [])
if (initialRoute === null) return <SplashScreen />Once getInitialLink() has been called, the listener never receives the launch link. If the listener already received it, getInitialLink() resolves null, and so does every call after the first.
getInitialLink() waits for the network when it has to:
| Situation | Waits for |
|---|---|
| The app was opened by a link | The resolve request (POST /v1/sdk/resolve) |
| First launch, no link | The launch report (POST /v1/sdk/init), because a deferred link may come back |
| Any later launch without a link | Nothing. Resolves null right away. |
Each request attempt has a 10 second timeout and failed requests are retried, so on a bad network this can take a while. Listening never blocks anything, which is why it is the recommended path.
Unresolved links
Not every URL is a Lander link, and the network is not always there. The SDK still delivers the link, with isResolved === false, confidence === 'unattributed' and only url set:
| Case | Why |
|---|---|
Lander answers 404 link_not_found | The URL is not a link of this project and environment: a page on your own site that your app also claims, a nested path, a typo, or a live link opened by an app using a pk_test_ key. |
Lander answers 410 | The link is disabled (link_disabled) or past its expiry (link_expired). |
| The request failed | Offline, timeout or a server error after retries. |
| Custom scheme URL | acmeshop://product/123 is delivered as is, with no network call. |
route still works for unresolved links. It uses the URL's path and query; for custom scheme URLs the host counts as the first path segment:
url | route |
|---|---|
acmeshop://product/123 | /product/123 |
acmeshop://product/123?color=red | /product/123?color=red |
https://acme.golander.link/old-slug (unknown) | /old-slug |
So design your navigation to cope with routes it does not know (a not found screen, or a redirect home).
One exception: a custom scheme URL that carries a short link in a lander_link query parameter (the iOS Continue in app page builds these) is resolved like the short link itself. url stays the scheme URL, and if resolving fails the scheme URL's own path still routes.
Other libraries' URLs
Every URL your app is opened with reaches your listener, including sign in redirects and other libraries' custom scheme URLs. Ignore routes you do not handle.
Route with React Navigation
React Navigation navigates by screen name, so map each route to a screen. The navigator may not be ready when the first link arrives, so keep it until onReady.
import { useRef } from 'react'
import { createNavigationContainerRef, NavigationContainer } from '@react-navigation/native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
import { type LanderLink, useLanderDeepLink } from 'react-native-lander'
import { HomeScreen, NotFoundScreen, ProductScreen } from './screens'
export type RootStackParamList = {
Home: undefined
Product: { id: string; link?: LanderLink }
NotFound: { route: string }
}
const Stack = createNativeStackNavigator<RootStackParamList>()
const navigationRef = createNavigationContainerRef<RootStackParamList>()
/** Maps a route such as /product/123 to a screen. */
function openLink(link: LanderLink) {
const path = link.route.split('?')[0] ?? '/'
const segments = path.split('/').filter(Boolean)
if (segments.length === 0) {
navigationRef.navigate('Home')
} else if (segments[0] === 'product' && segments[1]) {
// https://acme.golander.link/p-123 resolves to /product/123.
navigationRef.navigate('Product', { id: segments[1], link })
} else {
// Unresolved links route on the raw URL, which may match nothing.
navigationRef.navigate('NotFound', { route: link.route })
}
}
export default function App() {
const pending = useRef<LanderLink | null>(null)
// Subscribing here is enough: Lander buffers links (including the one that
// launched the app) until someone listens.
useLanderDeepLink((link) => {
if (navigationRef.isReady()) openLink(link)
else pending.current = link
})
return (
<NavigationContainer
ref={navigationRef}
onReady={() => {
if (pending.current) openLink(pending.current)
pending.current = null
}}
>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} options={{ title: 'Acme Shop' }} />
<Stack.Screen name="Product" component={ProductScreen} />
<Stack.Screen name="NotFound" component={NotFoundScreen} />
</Stack.Navigator>
</NavigationContainer>
)
}A few choices to make:
navigateorpush.navigategoes to an existingProductscreen if there is one;navigationRef.dispatch(StackActions.push('Product', ...))always stacks a new one. To reset the stack to home then the product (so back goes home), usenavigationRef.reset({ index: 1, routes: [{ name: 'Home' }, { name: 'Product', params } ] }).- Pass the link as a param.
LanderLinkis a plain object, so React Navigation does not warn about it. The screen can then readlink.params,link.campaignorlink.linkId(to attribute a purchase withtrackEvent). - Query parameters. If a link's path carries a query string (
/search?q=shoes), split it off before matching and read it with your own parser, or uselink.params, which already contains the opened URL's query parameters.
Links that need sign in
If a link points at a screen that needs an account, hold on to it and open it after sign in:
let pendingAfterSignIn: LanderLink | null = null
function onLink(link: LanderLink) {
if (!auth.isSignedIn) {
pendingAfterSignIn = link // open it once the user has signed in
navigationRef.navigate('SignIn')
return
}
openLink(link)
}
// After a successful sign in:
function onSignedIn() {
const link = pendingAfterSignIn
pendingAfterSignIn = null
if (link) openLink(link)
else navigationRef.navigate('Home')
}Here auth stands for your own auth state. Signing in is also the moment to call Lander.claimHandoff if you use handoffs.
Route with Expo Router
Expo Router routes are paths, so link.route can go straight to router.push. Two files are involved.
First, stop Expo Router from opening Lander URLs on its own. redirectSystemPath in app/+native-intent.tsx receives every URL the app is opened with (path is the full URL, initial is true for the launch URL). Returning null tells Expo Router to ignore it: on a cold start the app opens on its first screen, on a warm start it stays where it is.
// Your Lander domains and custom scheme. Lander delivers these through onDeepLink.
const LANDER_URL = /^(https?:\/\/acme\.golander\.link(\/|$)|acmeshop:)/i
export function redirectSystemPath({ path }: { path: string; initial: boolean }): string | null {
if (LANDER_URL.test(path)) return null
return path
}If your app also uses its custom scheme for something Expo Router should open (a sign in redirect, for example), match only the Lander domains here; custom scheme URLs then reach both Expo Router and your listener, so make the listener skip routes Expo Router handles.
Then listen in the root layout and push each link's route:
import { type Href, router, Stack } from 'expo-router'
import { Lander, useLanderDeepLink } from 'react-native-lander'
Lander.initialize({ apiKey: process.env.EXPO_PUBLIC_LANDER_KEY ?? '', enableLogging: __DEV__ })
export default function RootLayout() {
useLanderDeepLink((link) => {
// Expo Router params are strings, so pass the link ID along as a search
// param if a screen needs it for trackEvent.
const separator = link.route.includes('?') ? '&' : '?'
const href = link.linkId ? `${link.route}${separator}linkId=${link.linkId}` : link.route
router.push(href as Href)
})
return <Stack />
}app/product/[id].tsx then receives /product/123 with useLocalSearchParams() giving { id: '123', linkId: '...' }. Unknown routes land on your +not-found.tsx screen. Render a navigator (<Stack />, <Slot /> or tabs) on the first render of the root layout: Expo Router refuses to navigate before one is mounted.
Read the link's data
Params set on the link in Lander, plus any query parameters on the opened URL, are in link.params. Query parameters win when a key is in both, and arrive as strings.
const productId = link.params.productId // string | number | boolean | undefined
const discount = link.params.discount
if (link.campaign === 'summer_2026') {
// Show the campaign banner.
}For unresolved links params is empty. Read the raw URL's query instead, from link.url or the query part of link.route.