Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

UUID's avatar
Level 6

Prevent the page from refreshing when clicking on the link

I'm using the @algolia/autocomplete-js library in a Nuxt.js project to display search results for products and users. The problem I'm facing is that when I click on a search result link, the page refreshes instead of navigating within the SPA. I want to prevent the page from reloading and use Nuxt's router to navigate programmatically.


    item({ item, html }) {
              return html`
                <a href="${item.url}" class="flex items-center space-x-2">
                  <img src="${item.image}" class="w-20 h-20 rounded-full" />
                  <span>${item.title}</span>
                </a>
              `;
            },
0 likes
3 replies
vincent15000's avatar

With a simple link, you won't navigate inside the SPA.

<a href="${item.url}" class="flex items-center space-x-2">
	<img src="${item.image}" class="w-20 h-20 rounded-full" />
	<span>${item.title}</span>
</a>

To navigate inside the SPA, you need to use the NavLink vue-router component.

<RouterLink to="some-route">Link label</RouterLink>

In your project, it will probably by like this.

<RouterLink to="${item.url}" class="flex items-center space-x-2">
	<div>
		<img src="${item.image}" class="w-20 h-20 rounded-full" />
		<span>${item.title}</span>
	</div>
</RouterLink>

Make sure that inside the RouterLink component, you have a unique tag.

UUID's avatar
UUID
OP
Best Answer
Level 6

@vincent15000

I find this and works
https://www.algolia.com/doc/ui-libraries/autocomplete/integrations/using-vue/#customizing-templates

1 like

Please or to participate in this conversation.