Files
fizzy/app/javascript/controllers/back_navigation_controller.js
T
2024-11-05 13:04:05 -06:00

14 lines
344 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static values = { fallbackDestination: String }
connect() {
if (history.state.turbo?.restorationIndex > 0) {
this.element.href = "javascript:history.back()"
} else {
this.element.href = this.fallbackDestinationValue
}
}
}