Skip to content

Default behaviour of trailingSlash violated #11317

Closed

Description

@mledl

Describe the bug

SvelteKit will remove trailing slashes from URLs by default according to the docs. This functionality is not fully provided anymore since #10763 got merged.

Using the default value for paths.base the trailing slash will be added to any sub route like /home/foo/. However, this trailing slash will be removed after reloading the page. Moreover, in case of the default value for paths.base there is no trailing slash at root.

I would expect that the default behaviour of trailingSlash page option is still valid for default paths.base even after merging #10763.

Reproduction

A minimal repro example of the issue can be found in this repo.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 16.05 GB / 31.73 GB
  Binaries:
    Node: 20.9.0 - ~\AppData\Local\Volta\tools\image\node\20.9.0\node.EXE
    Yarn: 1.22.18 - ~\AppData\Local\Volta\tools\image\yarn\1.22.18\bin\yarn.CMD
    npm: 10.1.0 - ~\AppData\Local\Volta\tools\image\npm\10.1.0\bin\npm.CMD
    pnpm: 8.4.0 - ~\AppData\Local\Volta\bin\pnpm.EXE
  Browsers:
    Edge: Chromium (120.0.2210.61)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-node: ^1.3.1 => 1.3.1 
    @sveltejs/kit: ^1.30.3 => 1.30.3 
    svelte: ^4.2.2 => 4.2.8 
    vite: ^4.5.0 => 4.5.1

Severity

serious, but I can work around it

Additional Information

No response

Activity

  1. dangelomedinag commented on Dec 15, 2023

    @dangelomedinag

    same $page.url.pathname
    bug

  2. mass8326 commented on Dec 15, 2023

    @mass8326

    Ran into this in production! Was wondering why I was suddenly getting reports of 404s.

    Digging into this, I noticed several more things:

    • If the page you initially visit is root ("/"), all pages are treated as trailingSlash = "always" until you refresh the page
    • If the first page you visit is a subdirectory ("/"), trailingSlash is properly respected until you refresh the page
    • Using the browser back button at any point seems to cause trailingSlash become properly respected
    • Explicitly defining trailingSlash = "never" does not change this behavior
    • This issue exists in both SvelteKit 1.30.1 and 2.0.0

    Downgrading to 1.30.0 or earlier is my current solution

  3. added this to the soon milestone on Dec 16, 2023
  4. added a commit that references this issue on Feb 22, 2024
  5. th0rgall commented on May 13, 2024

    @th0rgall
    Contributor

    For people still bumping on this, the latest 1.x version at the time of writing (1.30.4) still has the code that causes the trailing slash to always be added on navigations from the root page.

    This was fixed in #11388 - but it seems that fix is only available in 2.x.

    So your options on ^1.30.1 are either downgrading to 1.30.0, as mentioned above here, or upgrading to 2.x.

  6. JTCorrin commented on May 19, 2024

    @JTCorrin

    For people still bumping on this, the latest 1.x version at the time of writing (1.30.4) still has the code that causes the trailing slash to always be added on navigations from the root page.

    This was fixed in #11388 - but it seems that fix is only available in 2.x.

    So your options on ^1.30.1 are either downgrading to 1.30.0, as mentioned above here, or upgrading to 2.x.

    I'm on kit v2.0.0 and have this bug. This:

    on:click={() => goto('/enterprise')}

    gives this in the address bar of the browser:

    http://localhost:5173/enterprise/

  7. bever1337 commented on Jul 17, 2025

    @bever1337

    Still relevant. Is there a new ticket tracking this issue? I'm using adapter-static so this bug is development-only in my case. Ideally, dev-mode routing mimics prod.

    "@sveltejs/adapter-static": "^3.0.8",
    "@sveltejs/kit": "^2.16.0",
    "@sveltejs/vite-plugin-svelte": "^5.0.0",
    "svelte": "^5.0.0",
    "vite": "^6.2.6",
    
  8. added theissue type on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions