File tree Expand file tree Collapse file tree
src/libs/Navigation/helpers/linkTo Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,21 @@ function areNamesAndParamsEqual(currentState: NavigationState<RootNavigatorParam
2929 return areNamesEqual && areParamsEqual ;
3030}
3131
32+ function arePathAndBackToEqual ( stateFromPath : PartialState < NavigationState < RootNavigatorParamList > > ) {
33+ const focusedRouteFromPath = findFocusedRoute ( stateFromPath ) ;
34+ const params = focusedRouteFromPath ?. params ?? { } ;
35+
36+ if ( ! focusedRouteFromPath ?. path || ! ( 'backTo' in params ) || ! params . backTo || typeof params . backTo !== 'string' ) {
37+ return false ;
38+ }
39+ let cleanedPath = focusedRouteFromPath . path . replace ( / \? .* / , '' ) ;
40+ let cleanedBackTo = params . backTo . replace ( / \? .* / , '' ) ;
41+ cleanedPath = cleanedPath . endsWith ( '/' ) ? cleanedPath . slice ( 0 , - 1 ) : cleanedPath ;
42+ cleanedBackTo = cleanedBackTo . endsWith ( '/' ) ? cleanedBackTo . slice ( 0 , - 1 ) : cleanedBackTo ;
43+
44+ return cleanedPath === cleanedBackTo ;
45+ }
46+
3247function shouldCheckFullScreenRouteMatching ( action : StackNavigationAction ) : action is StackNavigationAction & { type : 'PUSH' ; payload : { name : typeof NAVIGATORS . RIGHT_MODAL_NAVIGATOR } } {
3348 return action !== undefined && action . type === 'PUSH' && action . payload . name === NAVIGATORS . RIGHT_MODAL_NAVIGATOR ;
3449}
@@ -82,7 +97,7 @@ export default function linkTo(navigation: NavigationContainerRef<RootNavigatorP
8297 }
8398
8499 // We don't want to dispatch action to push/replace with exactly the same route that is already focused.
85- if ( areNamesAndParamsEqual ( currentState , stateFromPath ) ) {
100+ if ( areNamesAndParamsEqual ( currentState , stateFromPath ) || arePathAndBackToEqual ( stateFromPath ) ) {
86101 return ;
87102 }
88103
You can’t perform that action at this time.
0 commit comments