[🐞] useLocation URL searchParams is null #4956
Labels
STATUS-2: team is working on this
Scheduled for work by the core team
TYPE: bug
Something isn't working
WAITING FOR: team
Waiting for one of the core team members to review and reply
Which component is affected?
Qwik City (routing)
Describe the bug
Please note first that this bug appears only on SSG pages. It does not appear in dev mode.
using qwik v1.2.7. I have a page with parameters like
?id=7
, when I use a Link to navigate to that page thenconst id = loc.url.searchParams.get('id')
will correctly return the id '7' but when I reload/refresh the page or directly navigate to the page then It will return a null. Whileconst id = new URLSearchParams(document.location.search).get("id")
will correctly get the id '7'This issue does not appear on pnpm dev mode, it works correctly. It appears only in SSG using pnpm build then serve the dist folder using http-server or nginx.
Add this code to file src/routes/index.tsx:
Add the adapter SSG:
pnpm qwik add
then select: Adapter: Static site (.html files)Build the static html files with
pnpm build
then serve the dist folder withhttp-server ./dist
open the page giving it a parameter in the url like this
http://localhost:8080/?id=7
you should get and alert with message: id1 = 7 vs id2 = 7
but you will get this alert message: id1 = 7 vs id2 = null
Reproduction
https://stackblitz.com/edit/qwik-starter-9umyqd
Steps to reproduce
run:
pnpm i && pnpm build
thenhttp-server ./dist
. After that open /?id=7System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: