preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.02k stars 155 forks source link

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

Open developit opened 4 years ago

developit commented 4 years ago

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