DocSearch change URL from search UI

by Kevin_Granger

HTML

<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css">
<input id="q" type="search" />

<script type="text/javascript">
  docsearch({
    apiKey: '25626fae796133dc1e734c6bcaaeac3c',
    indexName: 'docsearch',
    inputSelector: '#q',
    transformData: function(hits) {
      // modify hits
      hits.map(hit => {
      	// If hit has an anchor, let's replace it with nothing and then slice to remove the #.
        // The console.log looks right, but the widget is still pointing to the URL with hash :(
        // Oddly, if you remove the `.slice(0, -1)`, it will start working - but it leaves a meaningless # at the end of the url :(
        	hit.url.replace(hit.anchor, '').slice(0, -1)
      })
      console.log(hits);
      return hits;
    },
    debug: false // Set debug to true if you want to inspect the dropdown
  });

</script>