Turbo Drive不拦截链接点击(但是Turbo:负载事件火灾)
我正在尝试将Turbo添加到Rails 6.1应用程序中。
它似乎正在加载(请参阅“我尝试过的内容”),但是在单击时,单击似乎并没有截获。我仍在全页重新加载。
谁能帮我发现这里缺少什么?
我尝试
- 使用console.log()输出添加了一个事件处理程序,该输出表明
turbo:load
的确被触发了 - ,确保了
turbo.session.drive = true = true
inapplication.js
- 甚至尝试将
data-turbo =“ true”
添加到< main>
标签,但这似乎没有任何区别。鉴于PT,也许并不奇怪。 2。Firefox - 和Chrome
设置
// app/javascript/application.js
import { Turbo } from "@hotwired/turbo-rails"
Turbo.session.drive = true
# config/importmap.rb
pin 'application', preload: true
pin '@hotwired/turbo-rails', to: 'turbo.js'
// Debugging statement
document.addEventListener('turbo:load', function() {
console.log('turbo:load');
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我发现仅包含Google Analytics(分析)4脚本标签
< head>
导致Turbo不起作用:原因? GA4的自动出站链接点击跟踪,我们已启用。有一个关于此的Github最新问题。正如评论中提到的:
方式继续前进。
So I found out that the mere inclusion of the Google Analytics 4 script tag in
<head>
caused Turbo not to work:The reason? GA4's automatic outbound link click tracking, which we have enabled. There's a very recent Github issue about this. As mentioned in a comment:
I disabled this feature in GA4, and was good to go.