Skip to content

How to navigate under the same path removing the query string using a href? #14890

@frederikhors

Description

@frederikhors

Describe the bug

I have this code in a Svelte 5 / SvelteKit 2 app:

<script lang="ts">
    import { resolve } from '$app/paths';

    // ...
</script>

{#each categories || [] as category (category.id)}
    <a href={resolve(`/categories/${category.id}`)}>
        {category.name}
    </a>
{/each}

If I add with another component a query string on the url like ?page=2 and then I click the link the query string is not automatically removed, why?

I'm already under /categories.

Example:

  • I'm on /categories/black?page=2
  • then I click on "Red"
  • it goes to /categories/red?page=2
  • I expect instead: /categories/red

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-hgoy6dcj?file=src%2Froutes%2Fcontact%2F%5Bid%5D%2F%2Bpage.svelte,src%2Flib%2Futil.svelte.ts

System Info

"@sveltejs/kit": "2.48.4",
"svelte": "5.43.3"

Severity

serious, but I can work around it

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions