Last active
October 3, 2024 08:42
-
-
Save firedev/cedf0ea3153e790498da5c72b33fcd76 to your computer and use it in GitHub Desktop.
Turbo Stream Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <turbo-stream action="reload" target="frame-id"></turbo-stream> | |
StreamActions.reload = function () { | |
document.getElementById(this.getAttribute("target"))?.reload() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Following the naming conventions | |
// https://github.com/marcoroth/turbo_power-rails#browser-history-actions | |
// | |
// <turbo-stream action="replace_state" url="URL"></turbo-stream> | |
window.addEventListener("turbo:load", () => { | |
document.addEventListener("turbo:before-stream-render", (event) => { | |
if (event.target.action === "replace_state") { | |
const url = event.target.attributes.url.value; | |
history.replaceState(null, null, url); | |
event.preventDefault(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment