You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently each component in a URLPattern produces a separate groups map. They are accessed like result.pathname.groups, result.hostname.groups, etc. This is a bit verbose and also requires the person accessing the groups to understand which named group the component is in.
We could instead try to expose a result.groups that combines all the matched values from all the components into one map.
The main issue is what to do for conflicting group names. For example, if both the hostname and pathname have :id groups. Or worse, what if both hostname and pathname have anonymous groups that get the 0 index name.
Maybe we could offer a convenience like result.uniqueGroups that contains any matched groups with a unique name. If you need a value that does not have a unique name then you have to go to result.pathname.groups.
The text was updated successfully, but these errors were encountered:
We currently have to iterate over different result groups and merge them into a single groups object with accumulative indexes. A single result.groups would be great to have.
The main issue is what to do for conflicting group names. For example, if both the hostname and pathname have :id groups. Or worse, what if both hostname and pathname have anonymous groups that get the 0 index name.
This is something I wanted to bring up as an issue in general (done in #226). I think URLPattern should support multiple same-named groups within the same component. If those are present, each match will be merged into an array of groups under the same name.
This also solves your concern above—multiple same-named groups in different URL components will be merged under the same result key. Each respective URL component result groups would contain the entire array (can be a getter to the root-level result.groups of the same name).
Currently each component in a URLPattern produces a separate
groups
map. They are accessed likeresult.pathname.groups
,result.hostname.groups
, etc. This is a bit verbose and also requires the person accessing the groups to understand which named group the component is in.We could instead try to expose a
result.groups
that combines all the matched values from all the components into one map.The main issue is what to do for conflicting group names. For example, if both the hostname and pathname have
:id
groups. Or worse, what if both hostname and pathname have anonymous groups that get the0
index name.Maybe we could offer a convenience like
result.uniqueGroups
that contains any matched groups with a unique name. If you need a value that does not have a unique name then you have to go toresult.pathname.groups
.The text was updated successfully, but these errors were encountered: