MatchRoute component fails with custom parse/stringify for numeric route params
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Router
Describe the bug
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.
Your Example Website or App
Steps to Reproduce the Bug or Issue
-
Define a route with a custom
parse/stringifyfor a numeric parameter, e.g.:const invoiceRoute = createRoute({ // ...other config path: '$invoiceId', params: { parse: (params) => ({ invoiceId: z.number().int().parse(Number(params.invoiceId)), }), stringify: ({ invoiceId }) => ({ invoiceId: `${invoiceId}` }), }, // ...rest of the route config }) -
Use the
MatchRoutecomponent with a numeric value:<MatchRoute to={invoiceRoute.to} params={{ invoiceId: 123, // Using a number }} pending > {(match) => <Spinner show={!!match} wait="delay-50" />} </MatchRoute> -
Observe that the match fails and the component doesn't render as expected.
-
Change the
invoiceIdto a string:<MatchRoute to={invoiceRoute.to} params={{ invoiceId: "123", // Using a string }} pending > {(match) => <Spinner show={!!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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the StackBlitz reproduction at src/main.tsx and inspect the MatchRoute and createRoute usage with the custom parse/stringify functions. Compare matching with numeric and string invoiceId values; done means MatchRoute renders successfully for both forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100