preact-router
preact-router copied to clipboard
Proposal: unmatched optional path segments produce undefined prop values
trafficstars
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