Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: generatePath doesn't work with optional params (v6.5.0-pre.1) #9736

Closed
jesperjohansson opened this issue Dec 16, 2022 · 3 comments · Fixed by #9764
Closed

[Bug]: generatePath doesn't work with optional params (v6.5.0-pre.1) #9736

jesperjohansson opened this issue Dec 16, 2022 · 3 comments · Fixed by #9764
Labels

Comments

@jesperjohansson
Copy link

jesperjohansson commented Dec 16, 2022

What version of React Router are you using?

6.5.0-pre.1

Steps to Reproduce

Reproduction demo: https://stackblitz.com/edit/github-kmv8on-hr7pvh?file=src/App.tsx

Attempt 1, path becomes /food/snacks/fruit/apple?/apples (with the ?) and wrong page is shown

<Link
  to={generatePath('food/:foodName/fruit/:fruitName?/apples', {
    foodName: 'snacks',
    fruitName: 'apple',
  })}
>
  Apples (generatePath)
</Link>

Attempt 2, throws error Missing ":fruitName" param

<Link
  to={generatePath('food/:foodName/fruit/:fruitName?/apples', {
    foodName: 'snacks',
    'fruitName?': 'apple',
  })}
>
  Apples (generatePath)
</Link>

Expected Behavior

Should had returned /food/snacks/fruit/apple/apples

Actual Behavior

Returns /food/snacks/fruit/apple?/apples

@brophdawg11
Copy link
Contributor

This is released in a 6.6.3-pre.0 prerelease if you want to give it a shot. Should have a stable out probably early next week

@jesperjohansson
Copy link
Author

@brophdawg11 Quick test seems to work https://stackblitz.com/edit/github-kmv8on-xzfgau?file=src/App.tsx

@brophdawg11
Copy link
Contributor

Released in 6.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants