I'm using a Bottom Tab Navigator with nested Stack Navigators for sections like "Home" and "Documents". Everything works fine in general.
**Navigation structure: **
TabNavigator
--- Home
--- DocumentsStack
------ DocumentsMain
------ DocumentsScreen2
------ DocumentsScreen3
However, i'm facing a weird behavior: when I open the app and directly access a shortcut from the Home screen that navigates to a nested screen (for example, "Home > DocumentsScreen2"):
navigation.navigate("documents", { screen: "documentsScreen2" });
It opens the screen correctly, but when I press back, it returns to Home, not to the main "DocumentsMain" screen, which is technically the root of the DocumentsStack.
The issue only happens if the user has not previously visited the "Documents" screen manually during the session. If they do visit "Documents" first, then go back to Home and use the shortcut, the behavior is correct (i.e., back navigates to "DocumentsMain").
When I navigate directly to a nested screen ("Home > DocumentsScreen2"), the stack is built with only that screen, so "DocumentsMain" is never mounted. Pressing back leaves the nested stack entirely and returns to Home.
How can I ensure that when navigating directly to a nested screen inside a stack, the base screen of that stack (DocumentsMain) is also part of the navigation stack, so that the back button works as expected?sMain) is also part of the navigation stack, so that the back button works as expected?
I tried navigating to the DocumentsMain screen first, followed by MeetingRecord, but this causes a visual flicker which leads to a bad user experience.