@@ -5,7 +5,7 @@ import Log from '@libs/Log';
55import buildTabNavigatorNestedState from '@libs/Navigation/helpers/buildTabNavigatorNestedState' ;
66import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath' ;
77import { isFullScreenName } from '@libs/Navigation/helpers/isNavigatorName' ;
8- import { SIDEBAR_TO_SPLIT } from '@libs/Navigation/linkingConfig/RELATIONS' ;
8+ import { SIDEBAR_TO_SPLIT , SPLIT_TO_SIDEBAR } from '@libs/Navigation/linkingConfig/RELATIONS' ;
99import type { NavigationPartialRoute } from '@libs/Navigation/types' ;
1010import CONST from '@src/CONST' ;
1111import NAVIGATORS from '@src/NAVIGATORS' ;
@@ -365,14 +365,19 @@ function handleReplaceFullscreenUnderRHP(
365365 }
366366 // Prepend the existing sidebar/root route (e.g. Inbox) to the incoming state when
367367 // it starts with a different screen, so back navigation from the new screen
368- // lands on the sidebar.
368+ // lands on the sidebar. When the existing tab doesn't have nested
369+ // routes (e.g. cold-start through a deep link that opens straight into a modal),
370+ // fall back to the split navigator's default sidebar route so there is still
371+ // something to pop back to.
369372 let mergedNestedState = focusedTargetTab . state ;
370373 const existingNestedRoutes = ( r . state as PartialState < NavigationState > | undefined ) ?. routes ;
371374 const newNestedRoutes = focusedTargetTab . state ?. routes ;
372375 const existingFirstRoute = existingNestedRoutes ?. at ( 0 ) ;
373376 const newFirstRoute = newNestedRoutes ?. at ( 0 ) ;
374- if ( existingFirstRoute && newFirstRoute && existingFirstRoute . name !== newFirstRoute . name ) {
375- const prependedRoutes = [ existingFirstRoute , ...( newNestedRoutes ?? [ ] ) ] ;
377+ const defaultSidebarRouteName = r . name in SPLIT_TO_SIDEBAR ? SPLIT_TO_SIDEBAR [ r . name as keyof typeof SPLIT_TO_SIDEBAR ] : undefined ;
378+ const sidebarRoute : NavigationPartialRoute | undefined = existingFirstRoute ?? ( defaultSidebarRouteName ? { name : defaultSidebarRouteName } : undefined ) ;
379+ if ( sidebarRoute && newFirstRoute && sidebarRoute . name !== newFirstRoute . name ) {
380+ const prependedRoutes = [ sidebarRoute , ...( newNestedRoutes ?? [ ] ) ] ;
376381 mergedNestedState = { ...focusedTargetTab . state , routes : prependedRoutes , index : prependedRoutes . length - 1 } ;
377382 }
378383 return {
0 commit comments