I see that it's possible to customize how search parameters get serialized by writing my own routingOptions
object as shown here: Configuration | Elastic docs
Can I customize selected parts of this, perhaps just the stateToUrl
and urlToState
functions? Basically, is there a way to access the default routingOptions
so I can merge/spread my custom functions with it?
Something like:
import { defaultRoutingOptions } from "@elastic/search-ui";
const routingOptions = {
...defaultRoutingOptions,
stateToUrl: (state) => {
const statesFilter = state.filters.find(
(filter) => filter.field === "states"
);
const states = statesFilter ? statesFilter.values.join(",") : "all";
return `/search/${states}?query=${state.searchTerm}`;
},
urlToState: (url) => {
const match = url.match(/\/search\/(\w+)\?query=(\w+)/);
if (!match) return {};
return {
searchTerm: match[2],
filters: [{ field: "states", values: [match[1].split(",")], type: "any" }]
};
}
};