Skip to content

Commit

Permalink
fix: Follow-up for #1573 to also handle the case when a non-default l…
Browse files Browse the repository at this point in the history
…ocale is in use (#1578)

Fixes #1568
  • Loading branch information
amannn authored Nov 26, 2024
1 parent aa2eb63 commit fd71741
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ describe("localePrefix: 'as-needed', custom `prefixes`", () => {
localePrefix: {
mode: 'as-needed',
prefixes: {
en: '/uk'
en: '/english',
de: '/deutsch'
}
}
});
Expand All @@ -563,6 +564,13 @@ describe("localePrefix: 'as-needed', custom `prefixes`", () => {
renderPathname();
screen.getByText('/about');
});

it('is tolerant when a locale is used in the pathname for a non-default locale', () => {
mockCurrentLocale('de');
mockLocation({pathname: '/de/about'});
renderPathname();
screen.getByText('/about');
});
});

describe("localePrefix: 'as-needed', with `basePath` and `domains`", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default function useBasePathname<
unlocalizedPathname = unprefixPathname(pathname, prefix);
} else if (
config.localePrefix.mode === 'as-needed' &&
config.defaultLocale === locale &&
config.localePrefix.prefixes
) {
// Workaround for https://github.com/vercel/next.js/issues/73085
Expand All @@ -58,5 +57,5 @@ export default function useBasePathname<
}

return unlocalizedPathname;
}, [config.defaultLocale, config.localePrefix, locale, pathname]);
}, [config.localePrefix, locale, pathname]);
}

0 comments on commit fd71741

Please sign in to comment.