You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/configuring-links.md
+49-4Lines changed: 49 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@ title: Configuring links
4
4
sidebar_label: Configuring links
5
5
---
6
6
7
+
import Tabs from '@theme/Tabs';
8
+
import TabItem from '@theme/TabItem';
9
+
7
10
In this guide, we will configure React Navigation to handle external links. This is necessary if you want to:
8
11
9
12
1. Handle deep links in React Native apps on Android and iOS
@@ -12,11 +15,45 @@ In this guide, we will configure React Navigation to handle external links. This
12
15
13
16
Make sure that you have [configured deep links](deep-linking.md) in your app before proceeding. If you have an Android or iOS app, remember to specify the [`prefixes`](navigation-container.md#linkingprefixes) option.
14
17
18
+
<TabsgroupId="config"queryString="config">
19
+
<TabItemvalue="static"label="Static"default>
20
+
21
+
The [`Navigation`](static-configuration.md#createstaticnavigation) component accepts a [`linking`](static-configuration.md#differences-in-the-linking-prop) prop that makes it easier to handle incoming links:
The `NavigationContainer` accepts a [`linking`](navigation-container.md#linking) prop that makes it easier to handle incoming links. The 2 of the most important properties you can specify in the `linking` prop are `prefixes` and `config`:
When you specify the `linking` prop, React Navigation will handle incoming links automatically. On Android and iOS, it'll use React Native's [`Linking` module](https://reactnative.dev/docs/linking) to handle incoming links, both when the app was opened with the link, and when new links are received when the app is open. On the Web, it'll use the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to sync the URL with the browser.
39
84
40
85
:::warning
@@ -43,7 +88,7 @@ Currently there seems to be bug ([facebook/react-native#25675](https://github.co
43
88
44
89
:::
45
90
46
-
You can also pass a [`fallback`](navigation-container.md#fallback) prop to `NavigationContainer` which controls what's displayed when React Navigation is trying to resolve the initial deep link URL.
91
+
You can also pass a [`fallback`](navigation-container.md#fallback) prop that controls what's displayed when React Navigation is trying to resolve the initial deep link URL.
47
92
48
93
## Prefixes
49
94
@@ -69,7 +114,7 @@ const linking = {
69
114
};
70
115
```
71
116
72
-
###Filtering certain paths
117
+
## Filtering certain paths
73
118
74
119
Sometimes we may not want to handle all incoming links. For example, we may want to filter out links meant for authentication (e.g. `expo-auth-session`) or other purposes instead of navigating to a specific screen.
75
120
@@ -85,7 +130,7 @@ const linking = {
85
130
86
131
This is not supported on Web as we always need to handle the URL of the page.
87
132
88
-
###Apps under subpaths
133
+
## Apps under subpaths
89
134
90
135
If your app is hosted under a subpath, you can specify the subpath at the top-level of the `config`. For example, if your app is hosted at `https://mychat.com/app`, you can specify the `path` as `app`:
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/static-configuration.md
+28-2Lines changed: 28 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -308,9 +308,35 @@ function App() {
308
308
}
309
309
```
310
310
311
-
This component is a wrapper around the `NavigationContainer` component and accepts the [same props and ref as the `NavigationContainer`](navigation-container.md) component. There's however one difference - the `linking` prop accepted by this component doesn't take a `config` property. Instead, the linking config is automatically inferred from the static config.
311
+
This component is a wrapper around the `NavigationContainer` component and accepts the [same props and ref as the `NavigationContainer`](navigation-container.md) component. It is intended to be rendered once at the root of your app similar to how you'd use `NavigationContainer` component.
312
312
313
-
This is intended to be rendered once at the root of your app similar to how you'd use `NavigationContainer` component.
313
+
### Differences in the `linking` prop
314
+
315
+
Similar to `NavigationContainer`, the component returned by `createStaticNavigation` also accepts a [`linking`](navigation-container.md#linking) prop. However, there are some key differences:
316
+
317
+
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).
318
+
2. The linking config is collected from the [`linking`](#linking) properties specified in the screen configuration.
319
+
3. It's possible to pass `enabled: 'auto'` to automatically generate paths for all leaf screens:
- Screens with an explicit `linking` property are not used for path generation and will be added as-is.
337
+
- Screen names will be converted from `PascalCase` to `kebab-case` to use as the path (e.g. `NewsFeed` -> `news-feed`).
338
+
- Unless a screen has explicit empty path (`path: ''`) to use for the homepage, the first leaf screen encountered will be used as the homepage.
339
+
- Path generation only handles leaf screens, i.e. no path is generated for screens containing nested navigators. It's still possible to specify a path for them with an explicit `linking` property.
The static configuration API provides the following benefits:
459
459
460
-
- Simpler type-checking with TypeScript, it's not necessary to specify screens and their params separately.
461
-
- Easier deep linking setup, the linking configuration can be defined next to the screen.
460
+
-**Simpler type-checking with TypeScript**: It's not necessary to specify screens and their params separately. See [Type checking with TypeScript](typescript.md?config=static) for more details.
461
+
-**Easier deep linking setup**: Paths can be generated automatically. Linking configuration can be defined next to the screen for explicit configuration. See [Configuring links](configuring-links.md?config=static) for more details.
462
462
463
463
It's also possible to mix the static and dynamic configuration APIs. For example, you can use the static configuration API for the top-level navigators and the dynamic configuration API for the nested navigators where you need more flexibility.
0 commit comments