diff --git a/versioned_docs/version-7.x/navigating.md b/versioned_docs/version-7.x/navigating.md
index 8fce9e37230..9a8ccd30d43 100755
--- a/versioned_docs/version-7.x/navigating.md
+++ b/versioned_docs/version-7.x/navigating.md
@@ -28,12 +28,14 @@ We'll do something similar to the latter, but rather than using a `window.locati
## Navigating to a new screen
-
-
-```js
+```js name="Navigating to a new screen" snack version=7
+// codeblock-focus-start
import * as React from 'react';
import { Button, View, Text } from 'react-native';
-import { NavigationContainer, useNavigation } from '@react-navigation/native';
+import {
+ createStaticNavigation,
+ useNavigation,
+} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
function HomeScreen() {
@@ -51,6 +53,29 @@ function HomeScreen() {
}
// ... other code from the previous section
+// codeblock-focus-end
+
+function DetailsScreen() {
+ return (
+
+ Details Screen
+
+ );
+}
+
+const RootStack = createNativeStackNavigator({
+ initialRouteName: 'Home',
+ screens: {
+ Home: HomeScreen,
+ Details: DetailsScreen,
+ },
+});
+
+const Navigation = createStaticNavigation(RootStack);
+
+export default function App() {
+ return ;
+}
```
Let's break this down:
@@ -66,11 +91,32 @@ If we call `navigation.navigate` with a route name that we haven't defined in a
So we now have a stack with two routes: 1) the `Home` route 2) the `Details` route. What would happen if we navigated to the `Details` route again, from the `Details` screen?
-## Navigate to a route multiple times
+## Navigate to a screen multiple times
+
+```js name="Navigate to a screen multiple times" snack version=7
+import * as React from 'react';
+import { Button, View, Text } from 'react-native';
+import {
+ createStaticNavigation,
+ useNavigation,
+} from '@react-navigation/native';
+import { createNativeStackNavigator } from '@react-navigation/native-stack';
-
+function HomeScreen() {
+ const navigation = useNavigation();
-```js
+ return (
+
+ Home Screen
+
+ );
+}
+
+// codeblock-focus-start
function DetailsScreen() {
const navigation = useNavigation();
@@ -84,19 +130,79 @@ function DetailsScreen() {
);
}
+// codeblock-focus-end
+
+const RootStack = createNativeStackNavigator({
+ initialRouteName: 'Home',
+ screens: {
+ Home: HomeScreen,
+ Details: DetailsScreen,
+ },
+});
+
+const Navigation = createStaticNavigation(RootStack);
+
+export default function App() {
+ return ;
+}
```
-If you run this code, you'll notice that when you tap "Go to Details... again" that it doesn't do anything! This is because we are already on the Details route. The `navigate` function roughly means "go to this screen", and if you are already on that screen then it makes sense that it would do nothing.
+If you run this code, you'll notice that when you tap "Go to Details... again", it doesn't do anything! This is because we are already on the Details route. The `navigate` function roughly means "go to this screen", and if you are already on that screen then it makes sense that it would do nothing.
Let's suppose that we actually _want_ to add another details screen. This is pretty common in cases where you pass in some unique data to each route (more on that later when we talk about `params`!). To do this, we can change `navigate` to `push`. This allows us to express the intent to add another route regardless of the existing navigation history.
-
+```js name="Navigate to a screen multiple times" snack version=7
+import * as React from 'react';
+import { Button, View, Text } from 'react-native';
+import {
+ createStaticNavigation,
+ useNavigation,
+} from '@react-navigation/native';
+import { createNativeStackNavigator } from '@react-navigation/native-stack';
-```js
-