Skip to content

fix: Ensure params aren't copied between partial matches#124

Merged
rschristian merged 1 commit intomainfrom
fix/clean-up-params-on-failed-match
Sep 26, 2025
Merged

fix: Ensure params aren't copied between partial matches#124
rschristian merged 1 commit intomainfrom
fix/clean-up-params-on-failed-match

Conversation

@rschristian
Copy link
Member

Fixes #123

Because each call of exec shared the same params obj, partial matches could get carried between attempts to find a matching child.

<Route path="/category/:id" component={Params} />
<Route path="/category/:categoryId/products/new" component={Params} />

When trying to load '/category/123/products/new', it'd test the first route, setting params up as { id: '123' }, and when that failed, the same params object was passed to the second test. It of course would match, but the params object would end up as { id: '123', categoryId: '123' }, keeping the incorrect id from the previous failed match.

...vnode.props,
path: rest,
query,
params: Object.assign({}, params),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Object.assign() is the only change, rest is just formatting as that line was getting rather long & hard to read.

@rschristian rschristian merged commit c8a8544 into main Sep 26, 2025
1 check passed
@rschristian rschristian deleted the fix/clean-up-params-on-failed-match branch September 26, 2025 14:01
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.

Unexpected behavior with multiple path params

2 participants