diff --git a/src/core/frames/frame_controller.js b/src/core/frames/frame_controller.js index 7487e4363..9edad47ac 100644 --- a/src/core/frames/frame_controller.js +++ b/src/core/frames/frame_controller.js @@ -14,7 +14,7 @@ import { } from "../../util" import { FormSubmission } from "../drive/form_submission" import { Snapshot } from "../snapshot" -import { getAction, expandURL, urlsAreEqual, locationIsVisitable } from "../url" +import { getAction, expandURL, urlsAreEqual, locationIsVisitable, isHashLink } from "../url" import { FormSubmitObserver } from "../../observers/form_submit_observer" import { FrameView } from "./frame_view" import { LinkInterceptor } from "./link_interceptor" @@ -480,6 +480,10 @@ export class FrameController { } #shouldInterceptNavigation(element, submitter) { + if (isHashLink(element)) { + return false + } + const id = getAttribute("data-turbo-frame", submitter, element) || this.element.getAttribute("target") if (element instanceof HTMLFormElement && !this.#formActionIsVisitable(element, submitter)) { diff --git a/src/core/session.js b/src/core/session.js index 1e9f1c7bd..86b2e8cbf 100644 --- a/src/core/session.js +++ b/src/core/session.js @@ -6,7 +6,7 @@ import { History } from "./drive/history" import { LinkPrefetchObserver } from "../observers/link_prefetch_observer" import { LinkClickObserver } from "../observers/link_click_observer" import { FormLinkClickObserver } from "../observers/form_link_click_observer" -import { getAction, expandURL, locationIsVisitable } from "./url" +import { getAction, expandURL, locationIsVisitable, isHashLink } from "./url" import { Navigator } from "./drive/navigator" import { PageObserver } from "../observers/page_observer" import { ScrollObserver } from "../observers/scroll_observer" @@ -252,6 +252,7 @@ export class Session { return ( this.elementIsNavigatable(link) && locationIsVisitable(location, this.snapshot.rootLocation) && + !isHashLink(link) && this.applicationAllowsFollowingLinkToLocation(link, location, event) ) } diff --git a/src/core/url.js b/src/core/url.js index 4b8f8ad68..86cef6f26 100644 --- a/src/core/url.js +++ b/src/core/url.js @@ -37,6 +37,10 @@ export function getLocationForLink(link) { return expandURL(link.getAttribute("href") || "") } +export function isHashLink(element) { + return element.getAttribute("href")?.startsWith("#") ?? false +} + export function getRequestURL(url) { const anchor = getAnchor(url) return anchor != null ? url.href.slice(0, -(anchor.length + 1)) : url.href diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index 86d19e633..173931d66 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -40,6 +40,7 @@