Skip to content

Commit fbf2a84

Browse files
committed
Don't refer to useLinking in NavigationContainer docs
1 parent 2021873 commit fbf2a84

File tree

2 files changed

+187
-35
lines changed

2 files changed

+187
-35
lines changed

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

Lines changed: 183 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ You can use it to track the focused screen, persist the navigation state etc.
8989
9090
### `linking`
9191
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.
9393
9494
Example:
9595
@@ -116,6 +116,186 @@ function App() {
116116
117117
See [configuring links guide](configuring-links.md) for more details on how to configure deep links and URL integration.
118118
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+
119299
### `fallback`
120300
121301
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 `
124304
125305
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:
126306
127-
#### `enabled`
307+
#### `documentTitle.enabled`
128308
129309
Whether document title handling should be enabled. Defaults to `true`.
130310
131-
#### `formatter`
311+
#### `documentTitle.formatter`
132312
133313
Custom formatter to use if you want to customize the title text. Defaults to:
134314

versioned_docs/version-5.x/use-linking.md

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ title: useLinking
44
sidebar_label: useLinking
55
---
66

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.
811

912
Example:
1013

@@ -176,37 +179,6 @@ The `parse` option controls how the params are parsed. Here, you can provide the
176179

177180
If no custom function is provided for parsing a param, it'll be parsed as a string.
178181

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-
210182
#### `enabled`
211183

212184
Optional boolean to enable or disable the linking integration. Defaults to `true`.

0 commit comments

Comments
 (0)