Skip to content

feat: ignore trailing slashes during route matching, configurable via trailingSlash prop#226

Merged
uhyo merged 1 commit into
masterfrom
claude/issue-209-normalize-config-0t6kzv
Jul 12, 2026
Merged

feat: ignore trailing slashes during route matching, configurable via trailingSlash prop#226
uhyo merged 1 commit into
masterfrom
claude/issue-209-normalize-config-0t6kzv

Conversation

@uhyo

@uhyo uhyo commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Closes #209

Problem

/users/ never matched route({ path: "users" }) (and vice versa) — URLPattern is strict about trailing slashes, and the router did no normalization. Worse, the strictness was inconsistent: prefix (parent) routes already tolerated a trailing slash via their {/*}? suffix, so /users/ could render fine or 404 depending on whether the route happened to have children.

Changes

  • Matching now ignores a single trailing slash by default. One trailing slash is stripped from the pathname and from route path patterns before matching. The root / is unaffected, only one slash is stripped (/users// is not repaired), and the URL itself is never rewritten — useLocation() still reports the pathname as-is.
  • The policy is configurable via a new trailingSlash prop on <Router>: "ignore" (default) or "strict" for the previous exact-match behavior. An enum (rather than a boolean) leaves room for a future "redirect"-style canonicalization mode.
  • All three match sites agree. The option is threaded through both render-time matchRoutes calls and the navigation-interception decision in NavigationAPIAdapter (via a new optional getMatchOptions getter on setupInterception), so the router never intercepts a navigation it won't render or vice versa.
  • Tests pin the policy: leaf/param/nested matching with trailing slashes, pattern-side slashes, root behavior, wildcard captures excluding the slash, no fall-through to catch-alls, strict mode, and Router-level tests covering rendering, URL non-rewriting, and interception.
  • Docs: new "Trailing Slashes" subsection in the Nested Routes guide and a trailingSlash row in the <Router> props table.

Release note

Default behavior changes: URLs with a trailing slash now match their slash-less route instead of falling through to a catch-all/404. Apps relying on the old strictness can opt back in with trailingSlash="strict". This should ship as at least a minor version with a changelog callout.

🤖 Generated with Claude Code

https://claude.ai/code/session_011JDF1rgn26iBR7XDT9riqv


Generated by Claude Code

… trailingSlash prop

A single trailing slash on the pathname (or on a route's path pattern)
never matched under URLPattern's strict semantics, so /users/ fell
through to the 404 branch while /users matched — and prefix (parent)
routes already tolerated the trailing slash, making the strictness
inconsistent. Matching now strips one trailing slash from both the
pathname and patterns by default; the URL itself is never rewritten.

The policy is configurable via a new trailingSlash prop on <Router>
("ignore" | "strict", default "ignore"), threaded through rendering and
the navigation interception decision so both always agree.

Closes #209

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011JDF1rgn26iBR7XDT9riqv
@uhyo
uhyo merged commit bea38ab into master Jul 12, 2026
1 check passed
@uhyo
uhyo deleted the claude/issue-209-normalize-config-0t6kzv branch July 12, 2026 04:17
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.

Trailing slashes never match — decide and document the policy

2 participants