Get the current URL in instantsearch.widgets.hits

Hi there,

We are using algolia for While we are generally quite happy with it and we’ve been able to figure out most ourselves (great docs, btw!) there is one thing we just can’t figure out or find documentation for.

Is there a way to get the current URL in instantsearch.widgets.hits?

The reason is obvious: Assuming, a visitor made refinements s/he should be able to further refine her/his search by clicking on, say, a category of an instantsearch.widgets.hits item. Currently, all prior refinements are ‘forgotten’ when an item’s link is clicked.

Hi! Thank you for your praise of the docs, they indeed are great! I forwarded your feedback to the team.

Regarding your question, I think you are generating the URL in the code of the custom component you’re passing to Hits.

When generating the URL for a category, you can take the URL of the current page and set the parameter of the category you’re generating the URL for (will add if not already there, and replace if it is).

Something like:

const url = new URL(document.location.href);
url.searchParams.set('speaks', 'German');
const categoryURL = url.toString();

Please, let us know how this goes!