Navigation object reference
The navigation object contains various convenience functions that dispatch navigation actions. It looks like this:
navigationnavigate- go to the given screen, this will behave differently based on the navigatorgoBack- go back to the previous screen, this will pop the current screen when used in a stackreset- replace the navigation state of the navigator with the given statepreload- preload a screen in the background before navigating to itsetParams- merge new params onto the route's paramsdispatch- send an action object to update the navigation statesetOptions- update the screen's optionsisFocused- check whether the screen is focusedcanGoBack- check whether it's possible to go back from the current screengetState- get the navigation state of the navigatorgetParent- get the navigation object of the parent screen, if anyaddListener- subscribe to events for the screenremoveListener- unsubscribe from events for the screen
The navigation object can be accessed inside any screen component with the useNavigation hook.
Screen components defined with the dynamic API also receive the navigation object as a prop. Consider it legacy and prefer using the useNavigation hook instead.
setParams/setOptions etc. should only be called in event listeners or useEffect/useLayoutEffect/componentDidMount/componentDidUpdate etc. Not during render or in constructor.
Navigator-dependent functions
There are several additional functions present on navigation object based on the kind of the current navigator.
If the navigator is a stack navigator, several alternatives to navigate and goBack are provided and you can use whichever you prefer. The functions are:
navigationreplace- replace the current screen with a new onepush- push a new screen onto the stackpop- go back in the stackpopTo- go back to a specific screen in the stackpopToTop- go to the top of the stack
See Stack navigator helpers and Native Stack navigator helpers for more details on these methods.
If the navigator is a tab navigator, the following are also available:
navigationjumpTo- go to a specific screen in the tab navigator
See Bottom Tab navigator helpers and Material Top Tab navigator helpers for more details on these methods.
If the navigator is a drawer navigator, the following are also available:
navigationjumpTo- go to a specific screen in the drawer navigatoropenDrawer- open the drawercloseDrawer- close the drawertoggleDrawer- toggle the state, ie. switch from closed to open and vice versa
See Drawer navigator helpers for more details on these methods.
Common API reference
The vast majority of your interactions with the navigation object will involve navigate, goBack, and setParams.
navigate
The navigate method lets us navigate to another screen in your app. It takes the following arguments:
navigation.navigate(name, params)
name- string - A destination name of the screen in the current or a parent navigator.params- object - Params to use for the destination route.options- Options object containing the following properties:merge- boolean - Whether params should be merged with the existing route params, or replace them (when navigating to an existing screen). Defaults tofalse.pop- boolean - Whether screens should be popped to navigate to a matching screen in the stack. Defaults tofalse.
- Static
- Dynamic
function HomeScreen() {
const navigation = useNavigation();
return (
<View
style={{
flex: 1,
gap: 8,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text>This is the home screen of the app</Text>
<Button
onPress={() => {
navigation.navigate('Profile', {
names: ['Brent', 'Satya', 'Michaś'],
});
}}
>
Go to Brent's profile
</Button>
</View>
);
}
function HomeScreen() {
const navigation = useNavigation();
return (
<View
style={{
flex: 1,
gap: 8,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text>This is the home screen of the app</Text>
<Button
onPress={() => {
navigation.navigate('Profile', {
names: ['Brent', 'Satya', 'Michaś'],
});
}}
>
Go to Brent's profile
</Button>
</View>
);
}
In a stack navigator (stack or native stack), calling navigate with a screen name will have the following behavior:
- If you're already on a screen with the same name, it will update its params and not push a new screen.
- If you're on a different screen, it will push the new screen onto the stack.
- If the
getIdprop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead. - If none of the above conditions match, it'll push a new screen to the stack.
In a tab or drawer navigator, calling navigate will switch to the relevant screen if it's not focused already and update the params of the screen.
navigateDeprecated
This method is deprecated and will be removed in a future release. It only exists for compatibility purposes. Use navigate instead.
The navigateDeprecated action implements the old behavior of navigate from previous versions.
It takes the following arguments:
navigation.navigateDeprecated(name, params)
name- string - A destination name of the screen in the current or a parent navigator.params- object - Params to use for the destination route.
In a stack navigator (stack or native stack), calling navigate with a screen name will have the following behavior:
- If you're already on a screen with the same name, it will update its params and not push a new screen.
- If you're on a different screen, it will push the new screen onto the stack.
- If the
getIdprop is specified, and another screen in the stack has the same ID, it will bring that screen to focus and update its params instead.
In a tab or drawer navigator, calling navigate will switch to the relevant screen if it's not focused already and update the params of the screen.
goBack
The goBack method lets us go back to the previous screen in the navigator.
By default, goBack will go back from the screen that it is called from:
- Static
- Dynamic
function ProfileScreen({ route }) {
const navigation = useNavigation();
return (
<View
style={{
flex: 1,
gap: 8,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text>Profile Screen</Text>
<Text>Friends: </Text>
<Text>{route.params.names[0]}</Text>
<Text>{route.params.names[1]}</Text>
<Text>{route.params.names[2]}</Text>
<Button onPress