withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.8k stars 2.49k forks source link

QueryParams are stripped #4399

Closed pbrissaud closed 2 years ago

pbrissaud commented 2 years ago

What version of astro are you using?

1.0.6

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

yarn

What operating system are you using?

Linux

Describe the Bug

When navigate to a page with querystring params, the Astro.url strip params and Astro.url.search and Astro.url.searchParams are empty.

Did I misunderstand something or is it a bug ?

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-nxwxap

Participation

FredKSchott commented 2 years ago

This is expected, because Astro builds a static site by default your build does not have access to search params. Only a server can see the search params, since they are passed by the user when the user makes a request, and static sites are built ahead of time without knowing what search params a user might send.

If you change output: 'server' in your config, Astro will stop stripping those values. Learn more: https://docs.astro.build/en/guides/server-side-rendering/

pbrissaud commented 2 years ago

Thanks @FredKSchott for your answer !

I resolved my problem by using a Vue component that can use window.location.href function to get params.

FredKSchott commented 2 years ago

sounds perfect!

vic-cekvenich commented 1 year ago

"Astro builds a static site by default your build does not have access to search params." This is a bug. That is not how http server(Apache, NGNIX) work, nor other static generators (eg 11ty). Search params are a browser command, so Astro removing it when it is client side is bug. I should not have to use server side just for querystring.

Re-opened: https://github.com/withastro/astro/issues/7489

BigWillie commented 1 year ago

I don't appear to be able to query the params from the server side either.

HananoshikaYomaru commented 7 months ago

if I set the config output to be hybrid and set the prerender of the page to be false, still the query params are stripped.