feat: ignore trailing slashes during route matching, configurable via trailingSlash prop#226
Merged
Merged
Conversation
… 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
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.
Closes #209
Problem
/users/never matchedroute({ 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
pathpatterns 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.trailingSlashprop 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.matchRoutescalls and the navigation-interception decision inNavigationAPIAdapter(via a new optionalgetMatchOptionsgetter onsetupInterception), so the router never intercepts a navigation it won't render or vice versa.trailingSlashrow 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