Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { navigator } from "@hotwired/turbo"
import { Controller } from "stimulus"
import { useMutation } from "stimulus-use"
export default class extends Controller {
connect(): void {
useMutation(this, { attributes: true })
}
mutate(entries: MutationRecord[]): void {
entries.forEach((mutation) => {
if (mutation.type === "attributes" && mutation.attributeName === "src") {
const src = this.element.getAttribute("src")
if (src)
navigator.history.push(new URL(src))
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment