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

3

8

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:

  • When I remove Turbolinks, the link behaves properly (does not cause page refresh).
  • Links with "#" as the URL cause a reload on every page of my app.
  • Links with any "#hasfragmenttext" will cause a single refresh and then the URL of the page is "mypage#hasfragmenttext", any additional clicks do NOT cause page refresh... hmm.
Lavinia answered 11/12, 2013 at 4:13 Comment(2)
Can you post content of head tag of generated page?Trevethick
had the same issue, this should not be the default behaviour, had to use github.com/turbolinks/…Loper
R
6

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

<a href="#" data-no-turbolink>My link</a>
Riojas answered 11/12, 2013 at 10:50 Comment(0)
L
23

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

Lota answered 30/9, 2016 at 1:25 Comment(2)
It also work for me, It looks better and it is included in official docs. It should be mark as answerTetragonal
Just to clarify this original solution was for classic turbolinks. This is for turbolinks 5Jocko
R
6

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

<a href="#" data-no-turbolink>My link</a>
Riojas answered 11/12, 2013 at 10:50 Comment(0)
B
2

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

data-turbo="false"
Backsword answered 13/5, 2022 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.