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
@@ -168,7 +165,7 @@ Here we have a stack navigator in root, and inside the `Home` screen of the root
168
165
}
169
166
```
170
167
171
-
In this config, we specify that the `Profile` screen should be resolved for the `users/:id` pattern and it's nested inside the `Home` screen. This will result in the following state object:
168
+
In this config, we specify that the `Profile` screen should be resolved for the `users/:id` pattern and it's nested inside the `Home` screen. Then parsing `users/jane` will result in the following state object:
172
169
173
170
```js
174
171
conststate= {
@@ -188,6 +185,46 @@ const state = {
188
185
};
189
186
```
190
187
188
+
Sometimes we want to ensure that a certain screen will always be present for the navigator in the state object. We can achieve it by specifying the `initialRouteName` property for that navigator in the config. For the above example, if we want the `Notifications` screen to be the initial route in `Home` tab navigator, we should specify such config (`Notifications` screen needn't be mentioned in `screens` property):
189
+
190
+
```js
191
+
{
192
+
Home: {
193
+
initialRouteName:'Notifications',
194
+
screens: {
195
+
Profile:'users/:id',
196
+
Notifications:'notify/:user',
197
+
},
198
+
},
199
+
};
200
+
```
201
+
202
+
Then, the path `/users/42` will resolve to the following state object:
203
+
204
+
```js
205
+
conststate= {
206
+
routes: [
207
+
{
208
+
name:'Home',
209
+
state: {
210
+
index:1,
211
+
routes: [
212
+
{
213
+
name:'Notifications',
214
+
},
215
+
{
216
+
name:'Profile',
217
+
params: { id:'jane' },
218
+
},
219
+
],
220
+
},
221
+
},
222
+
],
223
+
};
224
+
```
225
+
226
+
Notice that we can't pass any params to the `Notifications` screen if it isn't explicitly mentioned in the URL string, so the screen should implement handling lack of these params with e.g. providing default ones.
227
+
191
228
For some advanced cases, specifying the mapping may not be sufficient. You can implement your custom parser to address these cases using the `getStateFromPath` option:
0 commit comments