Skip to content

[Bug]: generatePath removes a parameter if it's value is 0 (number) #10593

@Shaddix

Description

@Shaddix

What version of React Router are you using?

6.12.1

Steps to Reproduce

generatePath('/product/:id', { id: 0 }) returns /products (expected: /products/0)

I know it's kinda not valid to pass 0 as a number, BUT it worked in 6.3.0 and before (so it's a regression). Also passing any other number works ok:
generatePath('/product/:id', { id: 1 }) returns /products/1
generatePath('/product/:id', { id: 2 }) returns /products/2
of course, passing 0 as string works as well
generatePath('/product/:id', { id: '0' }) returns /products/0

The fact that it works for other numbers could cause issues, because developers might use it, and then suddenly when the value is 0 it stops to work.

Expected Behavior

generatePath('/product/:id', { id: 0 }) -> /products/0

Actual Behavior

generatePath('/product/:id', { id: 0 }) -> /products

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions