Skip to content

Commit 3f962b1

Browse files
Fixes for linking
1 parent 42a5927 commit 3f962b1

File tree

1 file changed

+105
-26
lines changed

1 file changed

+105
-26
lines changed

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

Lines changed: 105 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,18 @@ For example, if we have `Catalog` screen inside `Home` screen and want it to han
499499

500500
```js
501501
const RootStack = createNativeStackNavigator({
502-
Home: {
503-
screens: {
504-
Catalog: {
505-
screen: Catalog,
506-
path: 'item/:id',
507-
parse: {
508-
id: Number,
502+
screens: {
503+
Home: {
504+
screen: HomeScreen,
505+
screens: {
506+
Catalog: {
507+
screen: Catalog,
508+
linking: {
509+
path: 'item/:id',
510+
parse: {
511+
id: Number,
512+
},
513+
},
509514
},
510515
},
511516
},
@@ -543,9 +548,13 @@ The options for parsing can be an object or a string:
543548

544549
```js
545550
const RootStack = createNativeStackNavigator({
546-
Catalog: {
547-
screen: Catalog,
548-
path: 'item/:id',
551+
screens: {
552+
Catalog: {
553+
screen: Catalog,
554+
linking: {
555+
path: 'item/:id',
556+
},
557+
},
549558
},
550559
});
551560
```
@@ -570,6 +579,34 @@ The `path` option is a pattern to match against the path. Any segments starting
570579

571580
The `initialRouteName` option ensures that the route name passed there will be present in the state for the navigator, e.g. for config:
572581

582+
<Tabs groupId="config" queryString="config">
583+
<TabItem value="static" label="Static" default>
584+
585+
```js
586+
const RootStack = createNativeStackNavigator({
587+
screens: {
588+
Home: {
589+
initialRouteName: 'Feed',
590+
screen: HomeScreen,
591+
linking: {
592+
screens: {
593+
Catalog: {
594+
path: 'item/:id',
595+
parse: {
596+
id: Number,
597+
},
598+
},
599+
Feed: 'feed',
600+
},
601+
},
602+
},
603+
},
604+
});
605+
```
606+
607+
</TabItem>
608+
<TabItem value="dynamic" label="Dynamic" default>
609+
573610
```js
574611
{
575612
screens: {
@@ -589,6 +626,9 @@ The `initialRouteName` option ensures that the route name passed there will be p
589626
}
590627
```
591628

629+
</TabItem>
630+
</Tabs>
631+
592632
and URL : `/item/42`, the state will look like this:
593633

594634
```js
@@ -615,6 +655,34 @@ and URL : `/item/42`, the state will look like this:
615655

616656
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:
617657

658+
<Tabs groupId="config" queryString="config">
659+
<TabItem value="static" label="Static" default>
660+
661+
```js
662+
const RootStack = createNativeStackNavigator({
663+
screens: {
664+
Home: {
665+
initialRouteName: 'Feed',
666+
screen: HomeScreen,
667+
linking: {
668+
screens: {
669+
Catalog: {
670+
path: 'item/:id',
671+
parse: {
672+
id: Number,
673+
},
674+
},
675+
Feed: 'feed',
676+
},
677+
},
678+
},
679+
},
680+
});
681+
```
682+
683+
</TabItem>
684+
<TabItem value="dynamic" label="Dynamic" default>
685+
618686
```js
619687
{
620688
screens: {
@@ -628,6 +696,9 @@ The `parse` option controls how the params are parsed. Here, you can provide the
628696
}
629697
```
630698

699+
</TabItem>
700+
</Tabs>
701+
631702
If no custom function is provided for parsing a param, it'll be parsed as a string.
632703

633704
##### `linking.enabled`
@@ -649,10 +720,12 @@ For example, you could do something like following to handle both deep linking a
649720
import messaging from '@react-native-firebase/messaging';
650721

651722
const RootStack = createNativeStackNavigator({
652-
Chat: {
653-
screen: Chat,
654-
linking: {
655-
path: 'feed/:sort',
723+
screens: {
724+
Chat: {
725+
screen: Chat,
726+
linking: {
727+
path: 'feed/:sort',
728+
},
656729
},
657730
},
658731
});
@@ -736,10 +809,12 @@ For example, you could do something like following to handle both deep linking a
736809
import messaging from '@react-native-firebase/messaging';
737810

738811
const RootStack = createNativeStackNavigator({
739-
Chat: {
740-
screen: Chat,
741-
linking: {
742-
path: 'feed/:sort',
812+
screens: {
813+
Chat: {
814+
screen: Chat,
815+
linking: {
816+
path: 'feed/:sort',
817+
},
743818
},
744819
},
745820
});
@@ -847,10 +922,12 @@ Example:
847922
import messaging from '@react-native-firebase/messaging';
848923

849924
const RootStack = createNativeStackNavigator({
850-
Chat: {
851-
screen: Chat,
852-
linking: {
853-
path: 'feed/:sort',
925+
screens: {
926+
Chat: {
927+
screen: Chat,
928+
linking: {
929+
path: 'feed/:sort',
930+
},
854931
},
855932
},
856933
});
@@ -907,10 +984,12 @@ Example:
907984
import messaging from '@react-native-firebase/messaging';
908985

909986
const RootStack = createNativeStackNavigator({
910-
Chat: {
911-
screen: Chat,
912-
linking: {
913-
path: 'feed/:sort',
987+
screens: {
988+
Chat: {
989+
screen: Chat,
990+
linking: {
991+
path: 'feed/:sort',
992+
},
914993
},
915994
},
916995
});

0 commit comments

Comments
 (0)