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-5.x/navigation-container.md
+183-3Lines changed: 183 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -89,7 +89,7 @@ You can use it to track the focused screen, persist the navigation state etc.
89
89
90
90
### `linking`
91
91
92
-
Configuration for linking integration used for deep linking and URL support in browsers. Accepts the same options as [`useLinking`](use-linking.md#options).
92
+
Configuration for linking integration used for deep linking and URL support in browsers.
93
93
94
94
Example:
95
95
@@ -116,6 +116,186 @@ function App() {
116
116
117
117
See [configuring links guide](configuring-links.md) for more details on how to configure deep links and URL integration.
118
118
119
+
#### Options
120
+
121
+
##### `linking.prefixes`
122
+
123
+
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/).
124
+
125
+
Only URLs matching these prefixes will be handled. The prefix will be stripped from the URL before parsing.
126
+
127
+
Example:
128
+
129
+
```js
130
+
<NavigationContainer
131
+
linking={{
132
+
prefixes: ['https://mychat.com', 'mychat://'],
133
+
config: {
134
+
screens: {
135
+
Chat:'feed/:sort',
136
+
},
137
+
},
138
+
}}
139
+
>
140
+
{/* content */}
141
+
</NavigationContainer>
142
+
```
143
+
144
+
This is only supported on iOS and Android.
145
+
146
+
##### `linking.config`
147
+
148
+
Config to fine-tune how to parse the path. The config object should represent the structure of the navigators in the app.
149
+
150
+
For example, if we have `Catalog` screen inside `Home` screen and want it to handle the `item/:id` pattern:
151
+
152
+
```js
153
+
{
154
+
screens: {
155
+
Home: {
156
+
screens: {
157
+
Catalog: {
158
+
path:'item/:id',
159
+
parse: {
160
+
id:Number,
161
+
},
162
+
},
163
+
},
164
+
},
165
+
}
166
+
}
167
+
```
168
+
169
+
The options for parsing can be an object or a string:
170
+
171
+
```js
172
+
{
173
+
screens: {
174
+
Catalog:'item/:id',
175
+
}
176
+
}
177
+
```
178
+
179
+
When a string is specified, it's equivalent to providing the `path` option.
180
+
181
+
The `path` option is a pattern to match against the path. Any segments starting with `:` are recognized as a param with the same name. For example `item/42` will be parsed to `{ name:'item', params: { id:'42' } }`.
182
+
183
+
The `initialRouteName` option ensures that the route name passed there will be present in the state for the navigator, e.g. for config:
184
+
185
+
```js
186
+
{
187
+
screens: {
188
+
Home: {
189
+
initialRouteName:'Feed',
190
+
screens: {
191
+
Catalog: {
192
+
path:'item/:id',
193
+
parse: {
194
+
id:Number,
195
+
},
196
+
},
197
+
Feed:'feed',
198
+
},
199
+
},
200
+
}
201
+
}
202
+
```
203
+
204
+
and URL : `/item/42`, the state will look like this:
205
+
206
+
```js
207
+
{
208
+
routes: [
209
+
{
210
+
name:'Home',
211
+
state: {
212
+
index:1,
213
+
routes: [
214
+
{
215
+
name:'Feed'
216
+
},
217
+
{
218
+
name:'Catalog',
219
+
params: { id:42 },
220
+
},
221
+
],
222
+
},
223
+
},
224
+
],
225
+
}
226
+
```
227
+
228
+
The `parse` option controls how the params are parsed. Here, you can provide the name of the param to parse as a key, and a function which takes the string value for the param and returns a parsed value:
229
+
230
+
```js
231
+
{
232
+
screens: {
233
+
Catalog: {
234
+
path:'item/:id',
235
+
parse: {
236
+
id:id=>parseInt(id, 10),
237
+
},
238
+
},
239
+
}
240
+
}
241
+
```
242
+
243
+
If no custom function is provided for parsing a param, it'll be parsed as a string.
244
+
245
+
##### `linking.enabled`
246
+
247
+
Optional boolean to enable or disable the linking integration. Defaults to `true` if the `linking` prop is specified.
248
+
249
+
##### `linking.getStateFromPath`
250
+
251
+
You can optionally override the way React Navigation parses deep links to a state object by providing your own implementation.
252
+
253
+
Example:
254
+
255
+
```js
256
+
<NavigationContainer
257
+
linking={{
258
+
prefixes: ['https://mychat.com', 'mychat://'],
259
+
config: {
260
+
screens: {
261
+
Chat:'feed/:sort',
262
+
},
263
+
},
264
+
getStateFromPath(path, config) {
265
+
// Return a state object here
266
+
// You can also reuse the default logic by importing `getStateFromPath` from `@react-navigation/native`
267
+
},
268
+
}}
269
+
>
270
+
{/* content */}
271
+
</NavigationContainer>
272
+
```
273
+
274
+
##### `linking.getPathFromState`
275
+
276
+
You can optionally override the way React Navigation serializes state objects to link by providing your own implementation. This is necessary for proper web support if you have specified `getStateFromPath`.
277
+
278
+
Example:
279
+
280
+
```js
281
+
<NavigationContainer
282
+
linking={{
283
+
prefixes: ['https://mychat.com', 'mychat://'],
284
+
config: {
285
+
screens: {
286
+
Chat:'feed/:sort',
287
+
},
288
+
},
289
+
getPathFromState(state, config) {
290
+
// Return a path string here
291
+
// You can also reuse the default logic by importing `getPathFromState` from `@react-navigation/native`
292
+
},
293
+
}}
294
+
>
295
+
{/* content */}
296
+
</NavigationContainer>
297
+
```
298
+
119
299
### `fallback`
120
300
121
301
React Element to use as a fallback while we resolve the deep link. Defaults to `null`.
@@ -124,11 +304,11 @@ React Element to use as a fallback while we resolve the deep link. Defaults to `
124
304
125
305
By default, React Navigation automatically updates the document title on Web to match the `title` option of the focused screen. You can disable it or customize it using this prop. It accepts a configuration object with the following options:
126
306
127
-
#### `enabled`
307
+
#### `documentTitle.enabled`
128
308
129
309
Whether document title handling should be enabled. Defaults to `true`.
130
310
131
-
#### `formatter`
311
+
#### `documentTitle.formatter`
132
312
133
313
Custom formatter to use if you want to customize the title text. Defaults to:
Copy file name to clipboardExpand all lines: versioned_docs/version-5.x/use-linking.md
+4-32Lines changed: 4 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,10 @@ title: useLinking
4
4
sidebar_label: useLinking
5
5
---
6
6
7
-
The `useLinking` hook lets us handle deep links in our apps. You probably want to use the [`linking` prop on `NavigationContainer`](navigation-container.md#linking) instead of using this hook directly.
7
+
The `useLinking` hook lets us handle deep links in our apps. This is used internally by React Navigation to implement deep linking support.
8
+
9
+
You should use the [`linking` prop on `NavigationContainer`](navigation-container.md#linking) instead of using this hook directly.
10
+
This documentation exists for users who were already using this hook before the `linking` prop was added.
8
11
9
12
Example:
10
13
@@ -176,37 +179,6 @@ The `parse` option controls how the params are parsed. Here, you can provide the
176
179
177
180
If no custom function is provided for parsing a param, it'll be parsed as a string.
178
181
179
-
Different segments of the same path can be handled by different parts of the config. For example, say we have the URL `/rooms/chat/jane`. We can provide the following config to handle it:
180
-
181
-
```js
182
-
{
183
-
screens: {
184
-
Rooms:'rooms',
185
-
Chat:'chat/:user'
186
-
}
187
-
}
188
-
```
189
-
190
-
This will result in the following navigation state:
191
-
192
-
```js
193
-
{
194
-
routes: [
195
-
{
196
-
name:'Rooms',
197
-
state: {
198
-
routes: [
199
-
{
200
-
name:'Chat',
201
-
params: { user:'jane' },
202
-
},
203
-
],
204
-
},
205
-
},
206
-
],
207
-
}
208
-
```
209
-
210
182
#### `enabled`
211
183
212
184
Optional boolean to enable or disable the linking integration. Defaults to `true`.
0 commit comments