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

独自空忆成欢 提交于 2019-12-06 06:20:22

问题


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.

回答1:


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

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



回答2:


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



来源:https://stackoverflow.com/questions/20510358/turbolinks-causes-a-link-with-href-to-trigger-page-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!