Skip to content

Commit e599ae8

Browse files
committed
fix pattern
1 parent 7fb6b3f commit e599ae8

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath';
66
import normalizePath from '@libs/Navigation/helpers/normalizePath';
77
import {linkingConfig} from '@libs/Navigation/linkingConfig';
88
import {shallowCompare} from '@libs/ObjectUtils';
9+
import getMatchingNewRoute from '@navigation/helpers/getMatchingNewRoute';
910
import type {NavigationPartialRoute, ReportsSplitNavigatorParamList, RootNavigatorParamList, StackNavigationAction} from '@navigation/types';
1011
import CONST from '@src/CONST';
1112
import NAVIGATORS from '@src/NAVIGATORS';
@@ -56,6 +57,7 @@ export default function linkTo(navigation: NavigationContainerRef<RootNavigatorP
5657
const {forceReplace} = {...defaultLinkToOptions, ...options} as Required<LinkToOptions>;
5758

5859
const normalizedPath = normalizePath(path) as Route;
60+
const normalizedPathAfterRedirection = (getMatchingNewRoute(normalizedPath) ?? normalizedPath) as Route;
5961

6062
// This is the state generated with the default getStateFromPath function.
6163
// It won't include the whole state that will be generated for this path but the focused route will be correct.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const oldRoutes: Record<string, string> = {
22
// eslint-disable-next-line @typescript-eslint/naming-convention
33
'/settings/workspaces/*': '/workspaces/',
4+
// eslint-disable-next-line @typescript-eslint/naming-convention
5+
'/settings/workspaces': '/workspaces',
46
};
57

68
export default oldRoutes;

tests/navigation/getMatchingNewRouteTest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ describe('getBestMatchingPath', () => {
55
expect(getMatchingNewRoute('/settings/workspaces/')).toBe('/workspaces/');
66
});
77

8+
it('returns mapped base path when input matches the exact pattern', () => {
9+
expect(getMatchingNewRoute('/settings/workspaces')).toBe('/workspaces');
10+
});
11+
812
it('returns mapped path when input matches the pattern and have more content', () => {
913
expect(getMatchingNewRoute('/settings/workspaces/anything/more')).toBe('/workspaces/anything/more');
1014
});

0 commit comments

Comments
 (0)