Anyone know if there’s a way to stop an <a data-turbo-frame="my-frame">...</a> tag from advancing history?
My use case is that I’m filling a <turbo-frame id="my-frame"> modal with the response from the server, and I don’t want that page fetch to appear in history when back or forward buttons are pressed.
Are you saying the when clicking on a link you have will 1) load the turbo-frame and 2) update the URL history on the page and when you click back it shows the same page, but without the turbo-frame? (advancing history)
OR…
Are you saying that when clicking on a link you have will 1) load the turbo-frame and 2) when click the back button it leaves the page (which had the turbo-frame), but when clicking the forward button you do not want the turbo-frame to still be rendered on the page? (caching)
I’m saying /resources/:resource/modal is what is requested by Turbo, and returned by, the server. (I’m not concerned with what’s shown in the browser bar at the moment—not using data-turbo-action.)
Weirdly the browser moves back to the right page (/resources) without making a request to the server. (I’m assuming this is caching.) But then it initiates a call to /resources/:resource/modal. I’m assuming it’s because that’s the last route Turbo added to History.
Is this not expected behavior? As far as I can tell, Turbo should be doing this—it can’t tell a modal request from any other frame. I only want to tell Turbo to act slightly differently, that is, to not recall this route from History.
Turbo is not altering the history, but rather Turbo caches the page when leaving and then restores the page from a turbo-cache when returning. When returning, it cached the URL of the turbo-frame before leaving the page.
Remove the turbo-frame before caching. This is a simple solution, although depending on your scenario it might break the page if wanting to re-initialize a turbo-frame after restoring the page via back/forward buttons.
Thank you! I was pulled to something else, so I was unable to give this a try. I’ll report back soon.
I admit, though, I’m still confused, because the documentation does talk about Drive pushing updates to the browser’s history:
Application visits result in a change to the browser’s history; the visit’s action determines how… The default visit action is advance . During an advance visit, Turbo Drives pushes a new entry onto the browser’s history stack using history.pushState.
But thank you, I’ll give this a try as soon as I can.