Skip to content

fix: trailing slash mismatch causes 404 for static routes#3721

Merged
bartlomieju merged 2 commits intomainfrom
fix/trailing-slashes-always-404
Mar 29, 2026
Merged

fix: trailing slash mismatch causes 404 for static routes#3721
bartlomieju merged 2 commits intomainfrom
fix/trailing-slashes-always-404

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Routes registered as /wissen now match requests for /wissen/ (and vice versa)
  • Fixes trailingSlashes("always") causing 404s on every file-based route

Problem

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), but trailingSlashes("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 passed
  • deno test -A packages/fresh/src/app_test.tsx — 46 passed

Closes #3644

🤖 Generated with Claude Code

bartlomieju and others added 2 commits March 28, 2026 09:49
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>
@bartlomieju bartlomieju merged commit caeebd8 into main Mar 29, 2026
8 of 9 checks passed
@bartlomieju bartlomieju deleted the fix/trailing-slashes-always-404 branch March 29, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Routes with trailing slashes no longer resolve in Fresh 2.2.0 when using file-based routing

1 participant