# Migration to v2

Two paths lead to `@swmansion/react-native-detour@2.0.0`. Pick the one that matches your current version:

- still on `0.x`: start from [From 0.x](#from-0x)
- already on `1.0.1`: start from [From 1.0.1](#from-101)

:::note[Device info provider from 2.3.0]
The steps below uninstall `react-native-device-info`, because `2.0.0` relied on `expo-device` alone. From **2.3.0** the SDK accepts either library, so keep `react-native-device-info` if your project already uses it. See [Device info provider](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation#device-info-provider).
:::

## From 0.x
### Changes from `0.x`

| Area | In `0.x` | In `2.0.0` |
| --- | --- | --- |
| Config key | Legacy `API_KEY` form in older integrations | `apiKey` |
| Link data in context | `linkRoute` / legacy fields | `link` object (`route`, `pathname`, `params`, `url`, `type`) |
| Link-source control | No explicit mode in older flows | `linkProcessingMode: 'all' \| 'web-only' \| 'deferred-only'` |
| Device fingerprint dependencies | `react-native-device-info` | `expo-constants` + `expo-device` |
| Expo Web behavior | Not explicitly guarded | `DetourProvider` disabled on web (no-op context) |

### 1. Update dependencies

Remove old dependency:

```bash
npm uninstall react-native-device-info
```

Install current peer dependencies:

```bash
npm install expo-localization expo-clipboard expo-constants expo-device @react-native-async-storage/async-storage expo-application
```

If you use Yarn/PNPM/Bun, use equivalent commands from [Installation](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation).

### 2. Update config shape

```ts
// before (legacy)
const config = {
  API_KEY: process.env.EXPO_PUBLIC_DETOUR_API_KEY,
  appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID,
};

// after
const config = {
  apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY,
  appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID,
  linkProcessingMode: 'all',
};
```

### 3. Update context usage

```ts
// before (legacy route string)
const { isLinkProcessed, linkRoute, clearLink } = useDetourContext();
if (isLinkProcessed && linkRoute) {
  router.replace(linkRoute);
  clearLink();
}

// after
const { isLinkProcessed, link, clearLink } = useDetourContext();
if (isLinkProcessed && link) {
  router.replace({ pathname: link.pathname, params: link.params });
  clearLink();
}
```

### 4. Choose a link processing mode

- `'all'` (default) — deferred + Universal/App + scheme links
- `'web-only'` — deferred + Universal/App links, no scheme links
- `'deferred-only'` — deferred only (recommended if Expo Router `+native-intent.tsx` handles runtime links)

## From 1.0.1
### Changes from `1.0.1`

| Area | In `1.0.1` | In `2.0.0` |
| --- | --- | --- |
| Device fingerprint dependencies | `react-native-device-info` | `expo-constants` + `expo-device` |
| Peer dependency install command | Included `react-native-device-info` | Uses Expo modules only (no `react-native-device-info`) |
| Expo Web behavior | Not explicitly guarded | `DetourProvider` is disabled on web (no-op context + one dev warning) |

### Update dependencies

1. Remove old dependency:

```bash
npm uninstall react-native-device-info
```

2. Install current peer dependencies:

```bash
npm install expo-localization expo-clipboard expo-constants expo-device @react-native-async-storage/async-storage expo-application
```

If you use Yarn/PNPM/Bun, use equivalent commands from [Installation](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation).

### Web behavior

In `2.0.0`, `DetourProvider` does not initialize on Expo Web. It returns a no-op context instead:

- `isLinkProcessed: true`
- `link: null`
- `clearLink: () => {}`

This keeps the app tree stable and avoids a partial initialization on a platform the SDK does not support.

## Validation checklist

Whichever path you took, confirm that:

1. The iOS and Android deferred flow still resolves the route and its parameters.
2. Runtime Universal/App Links still resolve according to `linkProcessingMode`.
3. Expo Web no longer attempts Detour processing, and the app renders without provider errors.
4. Exactly one `DetourProvider` is mounted in the app root.

## Related pages

- [Installation](https://detour.swmansion.com/docs/sdk/react-native/sdk-installation)
- [Usage](https://detour.swmansion.com/docs/sdk/react-native/sdk-usage)
- [API Reference](https://detour.swmansion.com/docs/sdk/react-native/api-reference)
- [Examples](https://detour.swmansion.com/docs/sdk/react-native/examples)