Scenario:
const Component = () => {
...
return (
<Pressable
...
onPress={() => router.push('[otherTab]/[screenWithinOtherTabStack]')}
>
...
}
...OtherTabNavigator()
return(
<Stack
...
screenOptions={{
...
headerLeft={() => (
<Pressable
onPress={() => router.back()}
...
>
...
router.back() will navigate to the [otherTab] rather than the tab/screen it originated fromThe pushed route seems to lose any state on routing.
I tried getting the key from the current path with useNavigation() and then navigating to '[otherTab]/[screenWithinOtherTabStack]' passing the key as a param, but I was unable to use the key to navigate back to the specific screens route that the push originated from.
If anyone has any insight to situation like this that have successfully handled, it would be greatly appreciated.
Each navigator keeps its own navigation history Nesting Navigators so what I did was to centralize the shared navigation logic in the outer navigator. This way, you can easily navigate to the desired screen from any tab.
Let's say you have a screen like (tabs)/post/[edit].tsx that you want to access from other tabs. Instead, move it up in your project structure. Now, you can navigate to this screen using a unified route like router.push(edit/${postId}) and keep track of the changes in history.
app
|-- (tabs)
| |-- post
| |-- comments
| |-- ...
|-- post
| |--[edit].tsx
|-- ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With