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:
parent
d71e937492
commit
feaba2c7fc
3 changed files with 15 additions and 10 deletions
5
.changeset/smart-cats-camp.md
Normal file
5
.changeset/smart-cats-camp.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix routing prefixes when `prefixDefaultLocale` is `true`
|
|
@ -10,7 +10,7 @@ type GetLocaleRelativeUrl = GetLocaleOptions & {
|
||||||
locales: Locales;
|
locales: Locales;
|
||||||
trailingSlash: AstroConfig['trailingSlash'];
|
trailingSlash: AstroConfig['trailingSlash'];
|
||||||
format: AstroConfig['build']['format'];
|
format: AstroConfig['build']['format'];
|
||||||
routingStrategy?: 'prefix-always' | 'prefix-other-locales';
|
routing?: 'prefix-always' | 'prefix-other-locales';
|
||||||
defaultLocale: string;
|
defaultLocale: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ export function getLocaleRelativeUrl({
|
||||||
path,
|
path,
|
||||||
prependWith,
|
prependWith,
|
||||||
normalizeLocale = true,
|
normalizeLocale = true,
|
||||||
routingStrategy = 'prefix-other-locales',
|
routing = 'prefix-other-locales',
|
||||||
defaultLocale,
|
defaultLocale,
|
||||||
}: GetLocaleRelativeUrl) {
|
}: GetLocaleRelativeUrl) {
|
||||||
const codeToUse = peekCodePathToUse(_locales, locale);
|
const codeToUse = peekCodePathToUse(_locales, locale);
|
||||||
|
@ -57,7 +57,7 @@ export function getLocaleRelativeUrl({
|
||||||
}
|
}
|
||||||
const pathsToJoin = [base, prependWith];
|
const pathsToJoin = [base, prependWith];
|
||||||
const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse;
|
const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse;
|
||||||
if (routingStrategy === 'prefix-always') {
|
if (routing === 'prefix-always') {
|
||||||
pathsToJoin.push(normalizedLocale);
|
pathsToJoin.push(normalizedLocale);
|
||||||
} else if (locale !== defaultLocale) {
|
} else if (locale !== defaultLocale) {
|
||||||
pathsToJoin.push(normalizedLocale);
|
pathsToJoin.push(normalizedLocale);
|
||||||
|
@ -88,7 +88,7 @@ type GetLocalesBaseUrl = GetLocaleOptions & {
|
||||||
locales: Locales;
|
locales: Locales;
|
||||||
trailingSlash: AstroConfig['trailingSlash'];
|
trailingSlash: AstroConfig['trailingSlash'];
|
||||||
format: AstroConfig['build']['format'];
|
format: AstroConfig['build']['format'];
|
||||||
routingStrategy?: 'prefix-always' | 'prefix-other-locales';
|
routing?: 'prefix-always' | 'prefix-other-locales';
|
||||||
defaultLocale: string;
|
defaultLocale: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ export function getLocaleRelativeUrlList({
|
||||||
path,
|
path,
|
||||||
prependWith,
|
prependWith,
|
||||||
normalizeLocale = false,
|
normalizeLocale = false,
|
||||||
routingStrategy = 'prefix-other-locales',
|
routing = 'prefix-other-locales',
|
||||||
defaultLocale,
|
defaultLocale,
|
||||||
}: GetLocalesBaseUrl) {
|
}: GetLocalesBaseUrl) {
|
||||||
const locales = toPaths(_locales);
|
const locales = toPaths(_locales);
|
||||||
|
@ -108,7 +108,7 @@ export function getLocaleRelativeUrlList({
|
||||||
const pathsToJoin = [base, prependWith];
|
const pathsToJoin = [base, prependWith];
|
||||||
const normalizedLocale = normalizeLocale ? normalizeTheLocale(locale) : locale;
|
const normalizedLocale = normalizeLocale ? normalizeTheLocale(locale) : locale;
|
||||||
|
|
||||||
if (routingStrategy === 'prefix-always') {
|
if (routing === 'prefix-always') {
|
||||||
pathsToJoin.push(normalizedLocale);
|
pathsToJoin.push(normalizedLocale);
|
||||||
} else if (locale !== defaultLocale) {
|
} else if (locale !== defaultLocale) {
|
||||||
pathsToJoin.push(normalizedLocale);
|
pathsToJoin.push(normalizedLocale);
|
||||||
|
|
|
@ -286,7 +286,7 @@ describe('getLocaleRelativeUrl', () => {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'en',
|
||||||
locales: ['en', 'es', 'en_US', 'en_AU'],
|
locales: ['en', 'es', 'en_US', 'en_AU'],
|
||||||
routingStrategy: 'prefix-always',
|
routing: 'prefix-always',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -530,7 +530,7 @@ describe('getLocaleRelativeUrlList', () => {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'en',
|
||||||
locales: ['en', 'en_US', 'es'],
|
locales: ['en', 'en_US', 'es'],
|
||||||
routingStrategy: 'prefix-always',
|
routing: 'prefix-always',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -840,7 +840,7 @@ describe('getLocaleAbsoluteUrl', () => {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'en',
|
||||||
locales: ['en', 'es', 'en_US', 'en_AU'],
|
locales: ['en', 'es', 'en_US', 'en_AU'],
|
||||||
routingStrategy: 'prefix-always',
|
routing: 'prefix-always',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1122,7 +1122,7 @@ describe('getLocaleAbsoluteUrlList', () => {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'en',
|
||||||
locales: ['en', 'en_US', 'es'],
|
locales: ['en', 'en_US', 'es'],
|
||||||
routingStrategy: 'prefix-always',
|
routing: 'prefix-always',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue