diff --git a/src/components/Navigation/NavigationTabBar/getLastRoute.ts b/src/components/Navigation/NavigationTabBar/getLastRoute.ts index e66a6e4177b3..1b5d6993e58c 100644 --- a/src/components/Navigation/NavigationTabBar/getLastRoute.ts +++ b/src/components/Navigation/NavigationTabBar/getLastRoute.ts @@ -10,7 +10,16 @@ function getLastRoute(rootState: NavigationState, navigator: ValueOf route.name === navigator)?.key; if (!lastNavigatorKey) { - const rootTabRoute = rootState.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR); + let rootTabRoute = rootState.routes.findLast((route) => { + if (route.name !== NAVIGATORS.TAB_NAVIGATOR) { + return false; + } + const tabState = getTabState(route); + return tabState?.routes?.[tabState.index ?? 0]?.name === navigator; + }); + if (!rootTabRoute) { + rootTabRoute = rootState.routes.findLast((route) => route.name === NAVIGATORS.TAB_NAVIGATOR); + } const tabState = getTabState(rootTabRoute); lastNavigatorKey = tabState?.routes?.findLast((route) => route.name === navigator)?.key; }