I'm writing a search application that allows filtering by certain search facets passed by the API, for example:
searchFacets: [
{
name: "color",
values: ["red", "green", "blue"],
},
{
name: "size",
values: ["small", "medium", "large"],
},
{
name: "age",
values: ["young", "old"],
},
]
When the user wants to filter search results by a certain facet, the API expects a request with selectedFacets
being a queryParam that is an object representing all selected facets:
selectedFacets: ["color=red", "size=medium"]
So currently, the URL for the request would look something like search?selectedFacets=["color=red", "size=medium"]&keyword=blah&someOtherParam=foo
However, I want the URL to show a deconstructed version of this selectedFacets object, while still retaining the object under the hood in the API request, so it would look something like search?color=red&size=medium&keyword=blah&someOtherParam=foo
The only problem is, I don't know the search facets (i.e. color, size, etc.) ahead of time, so I can't just specify them as queryParams in the route.
Is there a way to dynamically set queryParams programmatically, or translate a certain queryParam so it shows up this way in the URL?
Thanks!
Aucun commentaire:
Enregistrer un commentaire