Skip to content

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