Skip to content

Commit fd71741

Browse files
authored
fix: Follow-up for #1573 to also handle the case when a non-default locale is in use (#1578)
Fixes #1568
1 parent aa2eb63 commit fd71741

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/next-intl/src/navigation/react-client/createNavigation.test.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ describe("localePrefix: 'as-needed', custom `prefixes`", () => {
550550
localePrefix: {
551551
mode: 'as-needed',
552552
prefixes: {
553-
en: '/uk'
553+
en: '/english',
554+
de: '/deutsch'
554555
}
555556
}
556557
});
@@ -563,6 +564,13 @@ describe("localePrefix: 'as-needed', custom `prefixes`", () => {
563564
renderPathname();
564565
screen.getByText('/about');
565566
});
567+
568+
it('is tolerant when a locale is used in the pathname for a non-default locale', () => {
569+
mockCurrentLocale('de');
570+
mockLocation({pathname: '/de/about'});
571+
renderPathname();
572+
screen.getByText('/about');
573+
});
566574
});
567575

568576
describe("localePrefix: 'as-needed', with `basePath` and `domains`", () => {

packages/next-intl/src/navigation/react-client/useBasePathname.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export default function useBasePathname<
4747
unlocalizedPathname = unprefixPathname(pathname, prefix);
4848
} else if (
4949
config.localePrefix.mode === 'as-needed' &&
50-
config.defaultLocale === locale &&
5150
config.localePrefix.prefixes
5251
) {
5352
// Workaround for https://github.com/vercel/next.js/issues/73085
@@ -58,5 +57,5 @@ export default function useBasePathname<
5857
}
5958

6059
return unlocalizedPathname;
61-
}, [config.defaultLocale, config.localePrefix, locale, pathname]);
60+
}, [config.localePrefix, locale, pathname]);
6261
}

0 commit comments

Comments
 (0)