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

Proposal: unmatched optional path segments produce undefined prop values #382

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

developit
Copy link
Member

@developit developit commented Sep 23, 2020

Currently, optional path segments that do not match a current URL produce same-named props with an empty string value:

exec('/posts', '/posts/:user?/:id?', {})
// { user: "", id: "" }

exec('/posts/bob', '/posts/:user?/:id?', {})
// { user: "bob", id: "" }

With this PR, the value for optional path segments that have no match is an empty string. Matched path segments that are empty will still produce an empty string.

exec('/posts', '/posts/:user?/:id?', {})
// { user: undefined, id: undefined }

exec('/posts/bob', '/posts/:user?/:id?', {})
// { user: "bob", id: undefined }

This is a major change, because it means any defaultProps for route components will be applied for empty/missing route parameters - currently they are not.

Fixes #381.

ToDo

  • update tests

@developit developit changed the title Proposal: unmatched optional path segments should be undefined in props Proposal: unmatched optional path segments produce undefined prop values Sep 23, 2020
@developit developit changed the title Proposal: unmatched optional path segments produce undefined prop values Proposal: unmatched optional path segments produce undefined prop values Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional parameters result in empty strings?
1 participant