sveltejs / sveltejs/kit

Client router doesn't strip trailing slashes before redirecting

Open
#9,880 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

When navigating via link to a route that redirects, the client router doesn't
strip the trailing slash, causing the relative redirect to be based in the wrong
directory and the path to be foo/foo/bar instead of foo/bar.

If the link is opened in a new tab instead, everything works as expected.

Reproduction

https://github.com/zqianem/sveltekit-router-trailing-slash-bug

Open in StackBlitz

Logs

No response

System Info
System:
    OS: Linux 6.3 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
    Memory: 27.30 GB / 31.10 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 16.20.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/bin/npm
    Watchman: 20230222.123454.0 - /usr/bin/watchman
  Browsers:
    Chromium: 113.0.5672.63
    Firefox: 112.0.2
Severity

annoyance

Additional Information

Relevant docs: https://learn.svelte.dev/tutorial/trailingslash

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

Start with the linked reproduction at github.com/zqianem/sveltekit-router-trailing-slash-bug or its StackBlitz, then trace the client router's handling of a relative redirect from a trailing-slash route. Done means link navigation resolves to foo/bar rather than foo/foo/bar, while the new-tab behavior remains correct.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.