Returns the React Navigation object for the current route. This gives you low-level access to the underlying navigation state and methods.
Tip: Prefer useRouter for most navigation needs. It provides a simpler, strongly-typed API that’s designed specifically for One. Use useNavigation only when you need React Navigation-specific features.
| Parameter | Type | Description |
|---|---|---|
parent | string | Optional. Path to a parent navigator to get its navigation object |
You can access a parent navigator’s navigation object by providing a path:
Returns the React Navigation NavigationProp. Key methods include:
| Method | Description |
|---|---|
navigate(name, params) | Navigate to a screen |
goBack() | Go back to the previous screen |
isFocused() | Check if the screen is focused |
addListener(event, callback) | Subscribe to navigation events |
setOptions(options) | Update screen options |
getParent(id) | Get a parent navigator |
getState() | Get the navigation state |
dispatch(action) | Dispatch a navigation action |
Run code when a screen gains or loses focus:
Update screen options at runtime:
Prevent navigation (e.g., for unsaved changes):
Access methods from parent navigators in nested screens:
app/(tabs)/home/details.tsx
Access the current navigation state:
Available events you can listen to:
| Event | Description |
|---|---|
focus | Screen is focused |
blur | Screen loses focus |
beforeRemove | Screen is about to be removed (can be prevented) |
state | Navigation state changes |
| Use Case | Recommended Hook |
|---|---|
| Navigate to a route | useRouter |
| Go back | useRouter |
| Replace current route | useRouter |
| Listen to focus/blur events | useNavigation |
| Set screen options dynamically | useNavigation |
| Prevent navigation (beforeRemove) | useNavigation |
| Access navigation state | useNavigation |
| Access parent navigator | useNavigation |
Type the navigation object for better autocomplete:
Edit this page on GitHub.