-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Labels
needs triageIssue needs to be triagedIssue needs to be triaged
Description
Astro Info
Astro v5.9.3
Node v24.3.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I've noticed a weird behaviour with dynamic routing and Astro properties.
I was following the i18n documentation and have this code in my index.astro
export const getStaticPaths = async () => [
{ params: { locale: "en" } },
{ params: { locale: "de" } },
];
I decided to move the paths to another file so that I do not need to touch x files whenever I add another language:
import { i18nPaths } from "../../i18n/utils";
export const getStaticPaths = async () => i18nPaths;
Now I have the following problem:
I was trying to access Astro.url and Astro.currentLocale. But depending on where I put the getStaticPaths function they would be undefined or not:
Works:
console.log(Astro.url, Astro.currentLocale) // URL, en
export const getStaticPaths = async () => i18nPaths;
Does not work:
export const getStaticPaths = async () => i18nPaths;
console.log(Astro.url, Astro.currentLocale) // undefined, undefined
This behaviour does not occur when I inline the paths again:
Works:
export const getStaticPaths = async () => [
{ params: { locale: "en" } },
{ params: { locale: "de" } },
];
console.log(Astro.url, Astro.currentLocale); // URL, en
What's the expected result?
In my opinion this is valid too:
import { i18nPaths } from "../../i18n/utils";
export const getStaticPaths = async () => i18nPaths;
console.log(Astro.url, Astro.currentLocale) // this should give URL, en
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-znzuqhyl
Participation
- I am willing to submit a pull request for this issue.
Metadata
Metadata
Assignees
Labels
needs triageIssue needs to be triagedIssue needs to be triaged