0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

Fix i18n routing param (#9274)

* Fix i18n routing param

* Add changeset
This commit is contained in:
Reuben Tier 2023-12-04 05:00:01 +00:00 committed by GitHub
parent d71e937492
commit feaba2c7fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 10 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix routing prefixes when `prefixDefaultLocale` is `true`

View file

@ -10,7 +10,7 @@ type GetLocaleRelativeUrl = GetLocaleOptions & {
locales: Locales;
trailingSlash: AstroConfig['trailingSlash'];
format: AstroConfig['build']['format'];
routingStrategy?: 'prefix-always' | 'prefix-other-locales';
routing?: 'prefix-always' | 'prefix-other-locales';
defaultLocale: string;
};
@ -45,7 +45,7 @@ export function getLocaleRelativeUrl({
path,
prependWith,
normalizeLocale = true,
routingStrategy = 'prefix-other-locales',
routing = 'prefix-other-locales',
defaultLocale,
}: GetLocaleRelativeUrl) {
const codeToUse = peekCodePathToUse(_locales, locale);
@ -57,7 +57,7 @@ export function getLocaleRelativeUrl({
}
const pathsToJoin = [base, prependWith];
const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse;
if (routingStrategy === 'prefix-always') {
if (routing === 'prefix-always') {
pathsToJoin.push(normalizedLocale);
} else if (locale !== defaultLocale) {
pathsToJoin.push(normalizedLocale);
@ -88,7 +88,7 @@ type GetLocalesBaseUrl = GetLocaleOptions & {
locales: Locales;
trailingSlash: AstroConfig['trailingSlash'];
format: AstroConfig['build']['format'];
routingStrategy?: 'prefix-always' | 'prefix-other-locales';
routing?: 'prefix-always' | 'prefix-other-locales';
defaultLocale: string;
};
@ -100,7 +100,7 @@ export function getLocaleRelativeUrlList({
path,
prependWith,
normalizeLocale = false,
routingStrategy = 'prefix-other-locales',
routing = 'prefix-other-locales',
defaultLocale,
}: GetLocalesBaseUrl) {
const locales = toPaths(_locales);
@ -108,7 +108,7 @@ export function getLocaleRelativeUrlList({
const pathsToJoin = [base, prependWith];
const normalizedLocale = normalizeLocale ? normalizeTheLocale(locale) : locale;
if (routingStrategy === 'prefix-always') {
if (routing === 'prefix-always') {
pathsToJoin.push(normalizedLocale);
} else if (locale !== defaultLocale) {
pathsToJoin.push(normalizedLocale);

View file

@ -286,7 +286,7 @@ describe('getLocaleRelativeUrl', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'en_US', 'en_AU'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
@ -530,7 +530,7 @@ describe('getLocaleRelativeUrlList', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'en_US', 'es'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
@ -840,7 +840,7 @@ describe('getLocaleAbsoluteUrl', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'es', 'en_US', 'en_AU'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};
@ -1122,7 +1122,7 @@ describe('getLocaleAbsoluteUrlList', () => {
i18n: {
defaultLocale: 'en',
locales: ['en', 'en_US', 'es'],
routingStrategy: 'prefix-always',
routing: 'prefix-always',
},
},
};