#i have /[locale]/path/to/page but i also want i have /path/to/page to be available
1 messages · Page 1 of 1 (latest)
Hi @somber forge. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To achieve what you're looking for, you can use Astro's i18n routing configuration with the prefixDefaultLocale option set to false. This will allow you to have both localized paths (/[locale]/path/to/page) and a default path (/path/to/page) available.
Here's how you can configure this in your astro.config.mjs:
import { defineConfig } from "astro/config";
export default defineConfig({
i18n: {
defaultLocale: "en",
locales: ["en", "es", "fr"],
routing: {
prefixDefaultLocale: false
}
}
});
With this configuration:
/en/path/to/page,/es/path/to/page, and/fr/path/to/pagewill be available for their respective locales./path/to/pagewill be available and will serve the content for the default locale (in this case, English).
However, there are a few important points to note:
- Your default language content (English in this case) should be placed directly in the
src/pages/directory, not in a localized folder. - Other languages should have their content in their respective locale folders (e.g.,
src/pages/es/,src/pages/fr/).
Here's an example of how your file structure might look:
src/
pages/
path/
to/
page.astro (English version)
es/
path/
to/
page.astro (Spanish version)
fr/
path/
to/
page.astro (French version)
This setup allows you to have both /path/to/page (which serves the English content) and /[locale]/path/to/page for other languages.