ruby-on-railshotwire-railsturboturbo-frames

Rails + Hotwire: Why does my link disappear when I click it?


I'm trying to incorporate Hotwire/Turbo into an existing Rails application. I've added turbo frames to a simple edit page, but now when I click my back button, it disappears instead of taking me to target page. The link is a simple link_to "Back", my_model_show_path(model_instance).

I see that the network request takes place, and succeeds. The page preview in DevTools' Network tab shows the correct page being loaded and rendered as html. The browser just doesn't take me to the new location.

How do I make this work like before? I feel like I should be able to redirect anywhere in my application with regular links even if I'm using Hotwire/Turbo.


Solution

  • Turns out there are three ways (at least) to restore default link behavior.

    1: Set the data-turbo attribute.

    <%= link_to "Click Here", path_helper_method, data: { turbo: false } %>
    (or in plain html)
    <a href="" data-turbo="false">
    

    2: Set the target attribute.

    <%= link_to "Click Here", path_helper_method, target: "_top" %>
    (or in plain html)
    <a href="" target="_top">
    
    1. Move the link outside any Turbo frame. Any link inside a Turbo frame, without one of the above attributes, will be handled by Turbo by default.