The problem
I have a movie database with the indexName: 'movies'
.
Let's say my query is John
then the domain is domain.tld/?movies[query]=John
.
I want to simplify the search query parameter to domain.tld/?keywords=John
. How can I do that?
What I already know
After reading through the docs I know that I have to modify the createURL
and the parseURL
somehow:
createURL({ qsModule, location, routeState }) {
const { origin, pathname, hash } = location;
const indexState = routeState['movies'] || {};
const queryString = qsModule.stringify(routeState);
if (!indexState.query) {
return `${origin}${pathname}${hash}`;
}
return `${origin}${pathname}?${queryString}${hash}`;
},
...
parseURL({ qsModule, location }) {
return qsModule.parse(location.search.slice(1));
},
After some try and error here is a solution:
...