I'm using quite a new technology called Astro (https://astro.build/) to build a completely static, server side rendered page, shipping zero JS.
I have a page with a form that is a simple text input, when the user fills this in and clicks the submit button, it sends a GET request to an astro page. The url will look something like this ....
/?search=1234
What I want to be able to do is get access to that querystring parameter in order to redirect my user to another static page /1234.
I am trying to access the quesrystring parameter with Astro.request, but the object, including the parameters attribute is completely empty.
Is there anyway to access the querystring parameters from a .astro page/file?
you can use Astro.url
(available since v1.0.0-rc).
e.g.
---
const search = Astro.url.searchParams.get('search') || '';
---
{search ? <p>you searched for: {search}</p> : null}
<!-- rest of your template markup -->
I reached out to the developers of Astro and eventually had an email back. This functionality is not possible with Astro, it is not a bug, rather a misunderstanding from me about how Astro works. The pages in Astro are rendered up-front and are entirely static.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With