You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MatchRoute component fails with custom parse/stringify for numeric route params #2450
There's an issue with the MatchRoute component when used in conjunction with routes that have custom parse/stringify functions for handling numeric parameters. Specifically, the component fails to match when provided with a number, but works correctly when given a string.
Define a route with a custom parse/stringify for a numeric parameter, e.g.:
constinvoiceRoute=createRoute({// ...other configpath: '$invoiceId',params: {parse: (params)=>({invoiceId: z.number().int().parse(Number(params.invoiceId)),}),stringify: ({ invoiceId })=>({invoiceId: `${invoiceId}`}),},// ...rest of the route config})
Use the MatchRoute component with a numeric value:
<MatchRouteto={invoiceRoute.to}params={{invoiceId: 123,// Using a number}}pending>{(match)=><Spinnershow={!!match}wait="delay-50"/>}</MatchRoute>
Observe that the match fails and the component doesn't render as expected.
Change the invoiceId to a string:
<MatchRouteto={invoiceRoute.to}params={{invoiceId: "123",// Using a string}}pending>{(match)=><Spinnershow={!!match}wait="delay-50"/>}</MatchRoute>
Observe that the match now succeeds and the component renders correctly.
Expected behavior
The MatchRoute component should work correctly with both numeric and string values when a custom parse/stringify is defined for the route parameter.
Screenshots or Videos
No response
Platform
OS: macOS
Browser: Chrome
Version: 1.58.16
Additional context
This issue appears to be related to how the MatchRoute component interacts with the custom parse/stringify functions defined for route parameters. It seems that the component might be bypassing or incorrectly applying these functions when attempting to match the route.
Reacted by Thibault Van den broecke, oboe-ori, Tom Hicks, Valerii Petryniak, Ethan Potts and Olle Vidner
Found this while suffering with the same problem with useMatchRoute. Our url slugs can be formed either as IDs or as human-readable-prefixed IDs, e.g. /thing/abc123 or /thing/Title-of-the-thing-abc123.
I've just implemented the params.parse function in createRoute and it causes the useMatchRoute()({to: "/thing/$thingId", params: {thingId: passedDownFromParsedPathParams}) to fail to match. We're passing the parsed version of the ID, but the internal matching logic is using the original ID directly from the URL, presumably.
Types are also broken in this case. The param in my case is specified as number, but when I pass number - the matchRoute function always returns false. Passing string works as expected...
Activity
tests: reproducer for #2450
tomhicks commentedon Feb 17, 2026
Found this while suffering with the same problem with
useMatchRoute. Our url slugs can be formed either as IDs or as human-readable-prefixed IDs, e.g./thing/abc123or/thing/Title-of-the-thing-abc123.I've just implemented the
params.parsefunction increateRouteand it causes theuseMatchRoute()({to: "/thing/$thingId", params: {thingId: passedDownFromParsedPathParams})to fail to match. We're passing the parsed version of the ID, but the internal matching logic is using the original ID directly from the URL, presumably.valerii15298 commentedon Mar 4, 2026
Types are also broken in this case. The param in my case is specified as number, but when I pass number - the
matchRoutefunction always returns false. Passing string works as expected...