Skip to content

Commit 015b00d

Browse files
committed
Update deep link related docs
1 parent fad0382 commit 015b00d

8 files changed

Lines changed: 17 additions & 76 deletions

File tree

versioned_docs/version-7.x/deep-linking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This guide will describe how to configure your app to handle deep links on vario
1414

1515
React Native provides a [`Linking`](https://reactnative.dev/docs/linking) to get notified of incoming links. React Navigation can integrate with the `Linking` module to automatically handle deep links. On Web, React Navigation can integrate with browser's `history` API to handle URLs on client side. See [configuring links](configuring-links.md) to see more details on how to configure links in React Navigation.
1616

17-
While you don't need to use the `linking` prop from React Navigation, and can handle deep links yourself by using the `Linking` API and navigating from there, it'll be significantly more complicated than using the `linking` prop which handles many edge cases for you. So we don't recommend implementing it by yourself.
17+
We don't recommend handling deep links yourself using a [`ref`](navigation-container.md#ref) as it can be error-prone and significantly more complicated. Using the `linking` prop is the recommended way to handle deep links in React Navigation.
1818

1919
Below, we'll go through required configurations so that the deep link integration works.
2020

versioned_docs/version-7.x/web-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ While Web support works out of the box, there are some things to configure to en
1515

1616
1. [**Configure linking**](configuring-links.md)
1717

18-
Configuring linking allows React Navigation to integrate with the browser's URL bar. This is crucial for web apps to have proper URLs for each screen.
18+
Configuring linking allows React Navigation to integrate with the browser's URL bar, using the same configuration as for deep linking in React Native. This is crucial for web apps to have proper URLs for each screen.
1919

2020
2. **Use Button or Link components**
2121

versioned_docs/version-8.x/combine-static-with-dynamic.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ import { createPathConfigForStaticNavigation } from '@react-navigation/native';
195195
const feedScreens = createPathConfigForStaticNavigation(FeedTabs);
196196

197197
const linking = {
198-
prefixes: ['https://example.com', 'example://'],
199198
config: {
200199
screens: {
201200
Home: '',

versioned_docs/version-8.x/configuring-links.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const linking = {
121121

122122
If not specified, it defaults to `['*']`, which will match any host starting with `http`, `https`, and custom schemes such as `myapp://`.
123123

124-
You only need to specify `prefixes` if you're using **Expo Go** or want to restrict the URLs your app handles.
124+
You only need to specify `prefixes` if you're using [**Expo Go**](https://expo.dev/go) or want to restrict the URLs your app handles.
125125

126126
:::note
127127

@@ -385,7 +385,6 @@ const config = {
385385
};
386386

387387
const linking = {
388-
prefixes: ['https://example.com', 'example://'],
389388
config,
390389
};
391390

@@ -1557,7 +1556,6 @@ Example:
15571556
15581557
```js
15591558
const linking = {
1560-
prefixes: ['https://example.com', 'example://'],
15611559
getStateFromPath(path, options) {
15621560
// Return a state object here
15631561
// You can also reuse the default logic by importing `getStateFromPath` from `@react-navigation/native`

versioned_docs/version-8.x/deep-linking.md

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This guide will describe how to configure your app to handle deep links on vario
1414

1515
React Native provides a [`Linking`](https://reactnative.dev/docs/linking) to get notified of incoming links. React Navigation can integrate with the `Linking` module to automatically handle deep links. On Web, React Navigation can integrate with browser's `history` API to handle URLs on client side. See [configuring links](configuring-links.md) to see more details on how to configure links in React Navigation.
1616

17-
While you don't need to use the `linking` prop from React Navigation, and can handle deep links yourself by using the `Linking` API and navigating from there, it'll be significantly more complicated than using the `linking` prop which handles many edge cases for you. So we don't recommend implementing it by yourself.
17+
We don't recommend handling deep links yourself using a [`ref`](navigation-container.md#ref) as it can be error-prone and significantly more complicated. Using the `linking` prop is the recommended way to handle deep links in React Navigation.
1818

1919
Below, we'll go through required configurations so that the deep link integration works.
2020

@@ -56,9 +56,9 @@ See more details below at [Configuring React Navigation](#configuring-react-navi
5656
<details>
5757
<summary>Why use `Linking.createURL`?</summary>
5858

59-
It is necessary to use `Linking.createURL` since the scheme differs between the [Expo Dev Client](https://docs.expo.dev/versions/latest/sdk/dev-client/) and standalone apps.
59+
It is necessary to use `Linking.createURL` since the scheme differs between the [Expo Go](https://expo.dev/go) and standalone apps.
6060

61-
The scheme specified in `app.json` only applies to standalone apps. In the Expo client app you can deep link using `exp://ADDRESS:PORT/--/` where `ADDRESS` is often `127.0.0.1` and `PORT` is often `19000` - the URL is printed when you run `expo start`. The `Linking.createURL` function abstracts it out so that you don't need to specify them manually.
61+
The scheme specified in `app.json` only applies to standalone apps. In the Expo client (Expo Go or Dev Client) app you can deep link using `exp://ADDRESS:PORT/--/` where `ADDRESS` is often `127.0.0.1` and `PORT` is often `19000` - the URL is printed when you run `expo start`. The `Linking.createURL` function abstracts it out so that you don't need to specify them manually.
6262

6363
</details>
6464

@@ -283,55 +283,11 @@ Then, you need to [declare the association](https://developer.android.com/traini
283283

284284
## Configuring React Navigation
285285

286-
To handle deep links, you need to configure React Navigation to use the `scheme` for parsing incoming deep links:
286+
To handle deep links, you need to configure React Navigation based on the API you're using.
287287

288-
<Tabs groupId="config" queryString="config">
289-
<TabItem value="static" label="Static" default>
290-
291-
```js
292-
const linking = {
293-
prefixes: [
294-
'example://', // Or `Linking.createURL('/')` for Expo apps
295-
],
296-
};
297-
298-
function App() {
299-
return <Navigation linking={linking} />;
300-
}
301-
```
302-
303-
</TabItem>
304-
<TabItem value="dynamic" label="Dynamic">
305-
306-
```js
307-
const linking = {
308-
prefixes: [
309-
'example://', // Or `Linking.createURL('/')` for Expo apps
310-
],
311-
};
312-
313-
function App() {
314-
return (
315-
<NavigationContainer linking={linking} fallback={<Text>Loading...</Text>}>
316-
{/* content */}
317-
</NavigationContainer>
318-
);
319-
}
320-
```
288+
For static configuration, deep links are enabled by default with automatic path generation. So no additional configuration is needed. You can optionally customize the path patterns for specific screens if needed.
321289

322-
</TabItem>
323-
</Tabs>
324-
325-
If you are using universal links, you need to add your domain to the prefixes as well:
326-
327-
```js
328-
const linking = {
329-
prefixes: [
330-
'example://', // Or `Linking.createURL('/')` for Expo apps
331-
'https://app.example.com',
332-
],
333-
};
334-
```
290+
For dynamic configuration, deep links are enabled if you provide a `linking` prop to the `NavigationContainer`. The `linking` prop should contain mappings between path patterns and screens.
335291

336292
See [configuring links](configuring-links.md) to see further details on how to configure links in React Navigation.
337293

@@ -422,8 +378,6 @@ Here is an example integration with [expo-notifications](https://docs.expo.dev/v
422378

423379
```js name="Expo Notifications"
424380
const linking = {
425-
prefixes: ['example://', 'https://app.example.com'],
426-
427381
// Custom function to get the URL which was used to open the app
428382
async getInitialURL() {
429383
// First, handle deep links
@@ -468,8 +422,6 @@ const linking = {
468422
469423
```js name="Expo Notifications"
470424
const linking = {
471-
prefixes: ['example://', 'https://app.example.com'],
472-
473425
config: {
474426
// Deep link configuration
475427
},

versioned_docs/version-8.x/navigation-container.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,16 @@ function App() {
514514

515515
</TabItem>
516516
</Tabs>
517+
517518
See [configuring links guide](configuring-links.md) for more details on how to configure deep links and URL integration.
518519

519520
#### Options
520521

521522
##### `linking.prefixes`
522523

523-
URL prefixes to handle. You can provide multiple prefixes to support custom schemes as well as [universal links](https://developer.apple.com/ios/universal-links/).
524+
Optional URL prefixes to handle. By default, it matches any host starting with `http`, `https`, and custom schemes such as `myapp://` if this option is not specified.
525+
526+
You can provide multiple prefixes to support custom schemes as well as [universal links](https://developer.apple.com/ios/universal-links/) to explicitly handle certain prefixes.
524527

525528
Only URLs matching these prefixes will be handled. The prefix will be stripped from the URL before parsing.
526529

@@ -591,7 +594,6 @@ import messaging from '@react-native-firebase/messaging';
591594

592595
<Navigation
593596
linking={{
594-
prefixes: ['https://example.com', 'example://'],
595597
// highlight-start
596598
async getInitialURL() {
597599
// Check if app was opened from a deep link
@@ -621,7 +623,6 @@ import messaging from '@react-native-firebase/messaging';
621623

622624
<NavigationContainer
623625
linking={{
624-
prefixes: ['https://example.com', 'example://'],
625626
config: {
626627
// ...
627628
},
@@ -667,7 +668,6 @@ import messaging from '@react-native-firebase/messaging';
667668

668669
<Navigation
669670
linking={{
670-
prefixes: ['https://example.com', 'example://'],
671671
// highlight-start
672672
subscribe(listener) {
673673
const onReceiveURL = ({ url }: { url: string }) => listener(url);
@@ -709,7 +709,6 @@ import messaging from '@react-native-firebase/messaging';
709709

710710
<NavigationContainer
711711
linking={{
712-
prefixes: ['https://example.com', 'example://'],
713712
config: {
714713
// ...
715714
},
@@ -765,7 +764,6 @@ Example:
765764
```js
766765
<Navigation
767766
linking={{
768-
prefixes: ['https://example.com', 'example://'],
769767
// highlight-start
770768
getStateFromPath(path, config) {
771769
// Return a state object here
@@ -782,7 +780,6 @@ Example:
782780
```js
783781
<NavigationContainer
784782
linking={{
785-
prefixes: ['https://example.com', 'example://'],
786783
config: {
787784
// ...
788785
},
@@ -815,7 +812,6 @@ Example:
815812
```js
816813
<Navigation
817814
linking={{
818-
prefixes: ['https://example.com', 'example://'],
819815
// highlight-start
820816
getPathFromState(state, config) {
821817
// Return a path string here
@@ -832,7 +828,6 @@ Example:
832828
```js
833829
<NavigationContainer
834830
linking={{
835-
prefixes: ['https://example.com', 'example://'],
836831
config: {
837832
// ...
838833
},
@@ -865,7 +860,6 @@ Example:
865860
```js
866861
<Navigation
867862
linking={{
868-
prefixes: ['https://example.com', 'example://'],
869863
// highlight-start
870864
getActionFromState(state, config) {
871865
// Return a navigation action here
@@ -882,7 +876,6 @@ Example:
882876
```js
883877
<NavigationContainer
884878
linking={{
885-
prefixes: ['https://example.com', 'example://'],
886879
config: {
887880
// ...
888881
},

versioned_docs/version-8.x/static-configuration.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,13 @@ Similar to `NavigationContainer`, the component returned by `createStaticNavigat
366366

367367
1. It's not possible to pass a full `config` object to the `linking` prop. It can only accept [`path`](configuring-links.md#apps-under-subpaths) and an [`initialRouteName` for the root navigator](configuring-links.md#rendering-an-initial-route).
368368
2. The linking config is collected from the [`linking`](#linking) properties specified in the screen configuration.
369-
3. It's possible to pass `enabled: 'auto'` to automatically generate paths for all leaf screens:
369+
3. It defaults to `enabled: 'auto'` which enables deep links by default and automatically generate paths for all leaf screens.
370370

371371
```js
372372
const Navigation = createStaticNavigation(RootStack);
373373

374374
const linking = {
375-
enabled: 'auto',
376-
prefixes: ['https://example.com', 'example://'],
375+
path: '/app',
377376
};
378377

379378
function App() {
@@ -383,4 +382,4 @@ Similar to `NavigationContainer`, the component returned by `createStaticNavigat
383382

384383
See [How does automatic path generation work](configuring-links.md#how-does-automatic-path-generation-work) for more details.
385384

386-
By default, linking is enabled in static configuration with automatic path generation. It needs to be explicitly disabled by passing `enabled: false` to the `linking` prop if you don't want linking support.
385+
By default, linking is enabled in static configuration with automatic path generation. If you don't want linking support, it can be disabled by explicitly passing `enabled: false` to the `linking` prop.

versioned_docs/version-8.x/web-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ While Web support works out of the box, there are some things to configure to en
1515

1616
1. [**Configure linking**](configuring-links.md)
1717

18-
Configuring linking allows React Navigation to integrate with the browser's URL bar. This is crucial for web apps to have proper URLs for each screen.
18+
Configuring linking allows React Navigation to integrate with the browser's URL bar, using the same configuration as for deep linking in React Native. This is crucial for web apps to have proper URLs for each screen.
1919

2020
Automatic links are already enabled by default when using [Static configuration](static-configuration.md). So if you're using static configuration, you don't need to do anything to enable linking.
2121

0 commit comments

Comments
 (0)