fix: trailing slash mismatch causes 404 for static routes#3721
Merged
bartlomieju merged 2 commits intomainfrom Mar 29, 2026
Merged
fix: trailing slash mismatch causes 404 for static routes#3721bartlomieju merged 2 commits intomainfrom
bartlomieju merged 2 commits intomainfrom
Conversation
The router did exact-match on url.pathname for static routes, so a
route registered as `/wissen` would never match a request for `/wissen/`.
This broke `trailingSlashes("always")` — it redirected to the trailing
slash URL, but the router couldn't find the route.
Now the router tries the alternate trailing slash form when the exact
match fails. Routes registered as `/foo` match requests for `/foo/` and
vice versa.
Closes #3644
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Update comment to reflect that routes can be registered with or without trailing slashes, not just without. - Add test asserting exact match takes priority when both /path and /path/ are registered as separate routes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/wissennow match requests for/wissen/(and vice versa)trailingSlashes("always")causing 404s on every file-based routeProblem
The router's static route matching used exact string comparison on
url.pathname. File-based routes are registered without trailing slashes (e.g.routes/wissen/index.tsx→/wissen), buttrailingSlashes("always")redirects to/wissen/. After the redirect, the router can't find/wissen/because it only knows about/wissen.Fix
When the exact static match fails, the router now tries the alternate trailing slash form before falling through to dynamic routes. This is a single Map lookup — no performance impact on the happy path (exact match still checked first).
Test plan
deno test -A packages/fresh/src/router_test.ts— 11 passed (3 new tests)deno test -A packages/fresh/src/fs_routes_test.tsx— 55 passeddeno test -A packages/fresh/src/app_test.tsx— 46 passedCloses #3644
🤖 Generated with Claude Code