#searchParams doest work

3 messages · Page 1 of 1 (latest)

glacial drift
#

i'm trying to get an url param this way:

const email = Astro.url.searchParams.get('email') ;

halcyon iglooBOT
#

Hi @glacial drift. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In Astro, the Astro.request object is a standard Request (https://developer.mozilla.org/en-US/docs/Web/API/Request) object that can be used to get the url, headers, method, and even body of the request. However, with the default output: 'static' option, Astro.request.url does not contain search parameters, like ?foo=bar, as it’s not possible to determine them ahead of time during static builds.

If you are trying to get URL parameters during a static build, it won't work. However, in output: 'server' mode, Astro.request.url does contain search parameters as it can be determined from a server request.

Here is the reference from the Astro documentation (https://docs.astro.build/en/reference/api-reference/#astrorequest).

If you are in output: 'server' mode and still having issues, please ensure that the URL does indeed contain the 'email' parameter. If the problem persists, you might want to check your Astro version or consider seeking help from the Astro community or support.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: