Skip to content

Commit

Permalink
yoloing at 2024-09-11T16.45
Browse files Browse the repository at this point in the history
  • Loading branch information
byt3h3ad committed Sep 11, 2024
1 parent 47f8e10 commit 0594872
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions astro/search-params-in-astro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to get query strings in Astro

You can get the query string using [`Astro.url`](https://docs.astro.build/en/reference/api-reference/#astrourl) -

```js
const token = Astro.url.searchParams.get("access_token") || "";
```

However, Astro builds a static site by default. So this cannot access the 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.

Use [SSR](https://docs.astro.build/en/guides/server-side-rendering/) by changing `output: 'server'` in the config file or set `export const prerender = false;` on top of the page or route.

0 comments on commit 0594872

Please sign in to comment.