Skip to content

Commit a8a1e79

Browse files
authored
Merge pull request Expensify#65577 from daledah/fix/63976
fix: prevent navigation when path and backto is equal
2 parents 6637833 + ba9288c commit a8a1e79

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • src/libs/Navigation/helpers/linkTo

src/libs/Navigation/helpers/linkTo/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
3247
function 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

0 commit comments

Comments
 (0)