Skip to content

Add Option to Prevent URL Updates on Initial Render #143

@fromaline

Description

@fromaline

Describe the problem

Hey, thanks for the great library! It’s super handy for working with query parameters in SvelteKit.

I noticed that when you set a defaultValue, it updates the URL on the initial render if the parameter isn’t already there. For example:

const count = queryParam('count', {
  encode: (value: number) => value.toString(),
  decode: (value: string | null) => (value ? parseInt(value) : null),
  defaultValue: 10,
});

If I load /, it immediately changes the URL to /?count=10.
It would be nice to have an option to apply the default value without modifying the URL right away.

Describe the proposed solution

Maybe something like:

const count = queryParam('count', {
  encode: (value: number) => value.toString(),
  decode: (value: string | null) => (value ? parseInt(value) : null),
  defaultValue: 10,
  applyDefaultValueSilently: true,
});

This way, count would still default to 10 internally, but the URL stays clean until the user interacts with it.

Let me know if this makes sense or if there’s already a way to do this. Thanks again for your hard work on this library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions