I am trying to use beforeNavigate to preserve a query parameter in the URL if it is present. The important bit is as follows, in the root +layout.svelte file:
Now, if I run npm run dev and visit localhost:5173?test=true and start navigating between pages, the test param will be preserved for the first navigation, but not for navigations after that. This is because the from value passed to the beforeNavigate callback does not contain the query parameters that are in the actual URL for navigations after the first one following the query parameter being added.
The navigating store from $app/stores exhibits the same problematic behavior.
Describe the bug
I am trying to use
beforeNavigate
to preserve a query parameter in the URL if it is present. The important bit is as follows, in the root+layout.svelte
file:Now, if I run
npm run dev
and visitlocalhost:5173?test=true
and start navigating between pages, thetest
param will be preserved for the first navigation, but not for navigations after that. This is because thefrom
value passed to thebeforeNavigate
callback does not contain the query parameters that are in the actual URL for navigations after the first one following the query parameter being added.The
navigating
store from$app/stores
exhibits the same problematic behavior.The workaround is relatively simple:
Reproduction
Repro repository: https://github.com/Benaiah/repro-svelte-navigation-hook-bug
Instructions:
npm install
npm run dev
localhost:5173
)The logs attached are a copy of the console logs in the browser as this process is followed.
Logs
System Info
Severity
serious, but I can work around it
Additional Information
No response