Migration to v1
This guide helps migrate from older RN SDK integration patterns to @swmansion/react-native-detour@1.0.1.
Migration checklist
Section titled “Migration checklist”| Area | Before | In 1.0.1 |
|---|---|---|
| Config key | API_KEY | apiKey |
| Context shape | linkRoute, linkUrl, linkType exposed directly | link object (route, pathname, params, url, type) |
| Navigation mapping | Parse route string manually | Prefer link.pathname and link.params |
| Link-source control | No explicit mode | linkProcessingMode: 'all' | 'web-only' | 'deferred-only' |
| Expo Router native intent | Custom handler only | Optional createDetourNativeIntentHandler from @swmansion/react-native-detour/expo-router |
| Analytics import | legacy package/import variants | DetourAnalytics from @swmansion/react-native-detour |
Config update
Section titled “Config update”// beforeconst config = { API_KEY: process.env.EXPO_PUBLIC_DETOUR_API_KEY, appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID,};
// afterconst config = { apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY, appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID,};Context update (linkRoute -> link)
Section titled “Context update (linkRoute -> link)”// beforeconst { isLinkProcessed, linkRoute, clearLink } = useDetourContext();if (isLinkProcessed && linkRoute) { router.replace(linkRoute); clearLink();}
// afterconst { isLinkProcessed, link, clearLink } = useDetourContext();if (isLinkProcessed && link) { router.replace({ pathname: link.pathname, params: link.params }); clearLink();}Decide linkProcessingMode
Section titled “Decide linkProcessingMode”- Keep default
'all'when SDK should process deferred + web links + custom schemes. - Use
'web-only'when your app handles custom schemes separately. - Use
'deferred-only'when Expo Router native-intent flow already handles runtime/initial URLs.
Expo Router native-intent migration (optional)
Section titled “Expo Router native-intent migration (optional)”If your app uses Expo Router +native-intent.tsx, there are two potential link-processing layers:
- Expo Router
redirectSystemPath(before route resolution) - Detour runtime processing in
DetourProvider/useDetourContext()
Without explicit coordination, the same URL can be processed twice, or users can briefly land on an intermediate/unknown route before the final Detour route is resolved.
createDetourNativeIntentHandler is a helper that gives you a deterministic pre-routing step for Detour links. It can:
- match Detour hosts
- resolve short links using
apiKey+appID - map the resolved URL to a final Expo Router route
- return a safe
fallbackPathwhen resolution fails/timeouts
Recommended setup
Section titled “Recommended setup”- Add
createDetourNativeIntentHandlerinapp/+native-intent.tsx. - Set
linkProcessingMode: 'deferred-only'inDetourProviderso runtime/initial web links are not processed twice. - Keep
DetourProvidermounted for deferred matching and analytics.
import { createDetourNativeIntentHandler } from '@swmansion/react-native-detour/expo-router';
export const redirectSystemPath = createDetourNativeIntentHandler({ fallbackPath: '', config: { apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY!, appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID!, timeoutMs: 1200, },});
// app/_layout.tsxconst config = { apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY!, appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID!, linkProcessingMode: 'deferred-only',};If you need custom path shaping (for example dropping app-hash segment), use the handler mapToRoute callback.
Related resources
Section titled “Related resources”- Usage: Expo Router native intent helper
- Examples (
expo-router-native-intent,expo-router-advanced) - Expo Router docs: Customizing links with +native-intent
Validate after migration
Section titled “Validate after migration”- Trigger deferred link on fresh install and confirm
link?.type === 'deferred'. - Trigger runtime Universal/App Link and confirm
link?.type === 'verified'. - Trigger custom scheme link and confirm expected behavior for selected
linkProcessingMode. - Confirm only one
DetourProvideris mounted.