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 +