sveltejs / sveltejs/kit

Query parameters in hash routing become permanent if used "as directed"

Open
#14,592 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

router
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

In https://github.com/sveltejs/kit/pull/13191 there is a spirited discussion between Rich and the author as to how to handle query parameters in hash based routing.

Again, that's your choice. I will not; I will get my query parameters from page.url.searchParams, because I don't like to do work that's already been done for me.

Originally posted by @Rich-Harris in https://github.com/sveltejs/kit/issues/13191#issuecomment-2558122313

This implies that the intended "svelte" way to handle query parameters in hash based routing is with page.url.searchParams.

However -- when navigating between pages; the expected behaviour, ie, search parameters are deleted, does NOT occur. They become "permanent" search params.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-h6zoggpw?file=src%2Froutes%2F%2Blayout.svelte

  1. when opened, the footer says "You have no search params"
  2. click about page - "Your current query parameters are: aboutpage="
  3. click home - "Your current query parameters are: aboutpage="
Logs

System Info
System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.1 
    @sveltejs/kit: ^2.22.0 => 2.43.7 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.2.1 
    svelte: ^5.25.0 => 5.39.8 
    vite: ^7.0.4 => 7.1.8
Severity

serious, but I can work around it

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior in the linked StackBlitz example, starting with src/routes/+layout.svelte and the documented navigation steps. Trace how query parameters are read during hash-based navigation; done means moving from About to Home no longer retains aboutpage= when the destination has no search parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.