Created
September 26, 2023 14:25
-
-
Save Intrepidd/c8b7ede0c3628b7e8ad1fc9bdeccfd49 to your computer and use it in GitHub Desktop.
Turbo stream action to update the navigator history
This file contains hidden or 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
window.Turbo.StreamActions.advance_history = function () { | |
const url = new URL(this.getAttribute('url')) | |
window.Turbo.navigator.view.lastRenderedLocation = url | |
window.Turbo.navigator.history.push(url) | |
} |
This file contains hidden or 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
# frozen_string_literal: true | |
module TurboStreamAdditions | |
def advance_history(url) | |
turbo_stream_action_tag("advance_history", url: url) | |
end | |
end | |
Turbo::Streams::TagBuilder.prepend(TurboStreamAdditions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment