Navigation object reference
The navigation
object contains various convenience functions that dispatch navigation actions. It looks like this:
navigation
navigate
- 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. It's also passed as a prop only to screens components defined with the dynamic API.
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:
navigation
replace
- 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:
navigation
jumpTo
- 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:
navigation
jumpTo
- 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
.