Toni Michel Caubet
Toni Michel Caubet

Reputation: 20163

From a page in AstroJS [plugin:astro] location is not defined

In pages/index.astro if I try

---
console.log(location.href)
---

Then I get enter image description here

Error in text:

[plugin:astro] location is not defined

export statements in .astro files do not have access to local variable declarations, only imported values.

How can I access or import location from a AstroJs page?

Upvotes: 0

Views: 1815

Answers (1)

rschristian
rschristian

Reputation: 2956

location is a browser global. It doesn't exist in Node, which your Astro site will be built in.

Use Astro.url.href instead, the docs for which can be found here: https://docs.astro.build/en/reference/api-reference/#astrourl

Upvotes: 2

Related Questions