Don P
Don P

Reputation: 63768

Turbolinks causes a link with href="#" to trigger page refresh

I have a very simple link on my page. <a href="#">My link</a>. It causes a page refresh. when I remove "turbolinks", it no longer causes a refresh.

I've used links with hash fragments all the time in the past. Unless I've missed something very fundamental for a long time, I don't understand how this can cause a refresh.

It does not have any JS event handlers attached to it.

Any ideas?

It may not matter, but I'm using jQuery, Twitter-Bootstrap, and Ruby on Rails.

Clues so far:

Upvotes: 8

Views: 4492

Answers (3)

riley
riley

Reputation: 2467

With Rails 7 / Hotwire, you now need to use:

data-turbo="false"

Upvotes: 2

Anto Dominic
Anto Dominic

Reputation: 542

The above solution didn't work for me but this did :

<a href="#" data-turbolinks="false">My link</a>

This can be found at https://github.com/turbolinks/turbolinks

update: This solution works for turbolinks 5, for classic turbolinks check the previous answer by @wael34218

Upvotes: 23

wael34218
wael34218

Reputation: 4950

Use data-no-turbolink attribute on that link the error should be gone

<a href="#" data-no-turbolink>My link</a>

Upvotes: 6

Related Questions