Skip to content

Commit b1359c1

Browse files
Migrate 'Route object' examples to static API in v7 (#1321)
1 parent e93be02 commit b1359c1

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

versioned_docs/version-7.x/route-object.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Route object reference
44
sidebar_label: Route object
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
Each `screen` component in your app is provided with the `route` object as a prop automatically. The prop contains various information regarding current route (place in navigation hierarchy component lives).
811

912
- `route`
@@ -12,9 +15,51 @@ Each `screen` component in your app is provided with the `route` object as a pro
1215
- `path` - An optional string containing the path that opened the screen, exists when the screen was opened via a deep link.
1316
- `params` - An optional object containing params which is defined while navigating e.g. `navigate('Twitter', { user: 'Dan Abramov' })`.
1417

15-
<samp id="route-prop" />
18+
<Tabs groupId="config" queryString="config">
19+
<TabItem value="static" label="Static" default>
20+
21+
```js name="Route prop" snack version=7
22+
import * as React from 'react';
23+
import { View, Text } from 'react-native';
24+
import { createStaticNavigation } from '@react-navigation/native';
25+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
26+
27+
const Stack = createNativeStackNavigator({
28+
screens: {
29+
Profile: ProfileScreen,
30+
},
31+
});
32+
33+
// codeblock-focus-start
34+
function ProfileScreen({ route }) {
35+
return (
36+
<View>
37+
<Text>This is the profile screen of the app</Text>
38+
<Text>{route.name}</Text>
39+
</View>
40+
);
41+
}
42+
// codeblock-focus-end
43+
44+
const Navigation = createStaticNavigation(Stack);
45+
46+
export default function App() {
47+
return <Navigation />;
48+
}
49+
```
50+
51+
</TabItem>
52+
<TabItem value="dynamic" label="Dynamic" default>
53+
54+
```js name="Route prop" snack version=7
55+
import * as React from 'react';
56+
import { View, Text } from 'react-native';
57+
import { NavigationContainer } from '@react-navigation/native';
58+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
1659

17-
```js
60+
const Stack = createNativeStackNavigator();
61+
62+
// codeblock-focus-start
1863
function ProfileScreen({ route }) {
1964
return (
2065
<View>
@@ -23,4 +68,18 @@ function ProfileScreen({ route }) {
2368
</View>
2469
);
2570
}
71+
// codeblock-focus-end
72+
73+
export default function App() {
74+
return (
75+
<NavigationContainer>
76+
<Stack.Navigator>
77+
<Stack.Screen name="Profile" component={ProfileScreen} />
78+
</Stack.Navigator>
79+
</NavigationContainer>
80+
);
81+
}
2682
```
83+
84+
</TabItem>
85+
</Tabs>

0 commit comments

Comments
 (0)