1import { Controller } from "@hotwired/stimulus"; 2 3// data-controller="turbo-router" 4export default class extends Controller { 5 connect() { 6 // 1) Clicked links / programmatic visits 7 this.beforeVisit = (event) => { 8 const url = new URL(event.detail.url, window.location.href); 9 if (this.shouldReload(url)) { 10 event.preventDefault(); 11 window.location.href = url.href; 12 } 13 }; 14 15 // 2) Any Turbo fetch (Drive or Frames). Good for edge cases. 16 this.beforeFetchRequest = (event) => { 17 const raw = event.detail.url || event.detail.fetchOptions?.url; 18 const url = new URL(raw, window.location.href); 19 if (this.shouldReload(url)) { 20 event.preventDefault(); 21 window.location.href = url.href; 22 } 23 }; 24 25 document.addEventListener("turbo:before-visit", this.beforeVisit); 26 document.addEventListener("turbo:before-fetch-request", this.beforeFetchRequest); 27 } 28 29 disconnect() { 30 document.removeEventListener("turbo:before-visit", this.beforeVisit); 31 document.removeEventListener("turbo:before-fetch-request", this.beforeFetchRequest); 32 } 33 34 shouldReload(url) { 35 // Same-origin check (we only care about paths on this origin) 36 if (url.origin !== window.location.origin) return false; 37 // Everything under /identity/ should be a hard navigation 38 return url.pathname.startsWith("/identity/"); 39 } 40}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.