Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ We use [Break Versioning][breakver]. The version numbers follow a `<major>.<mino

[breakver]: https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md

## UNRELEASED

* **reitit-frontend**: `Html5History` no longer handles anchor clicks whose default action has already been prevented. [#803](https://github.com/metosin/reitit/pull/803)

## 0.11.0 (2026-09-18)

* Add support for `QUERY` method. [#786](https://github.com/metosin/reitit/pull/786)
Expand Down
2 changes: 2 additions & 0 deletions modules/reitit-frontend/src/reitit/frontend/history.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
(.getDomain ^goog.Uri (.parse goog.Uri js/location)))]
(and (or (and (not (.hasScheme uri)) (not (.hasDomain uri)))
(= current-domain (.getDomain uri)))
;; A listener closer to the anchor has already cancelled the navigation.
(not (.-defaultPrevented e))
(not (.-altKey e))
(not (.-ctrlKey e))
(not (.-metaKey e))
Expand Down
21 changes: 21 additions & 0 deletions test/cljs/reitit/frontend/history_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,24 @@

(reset! clicks [document-link shadow-link])
(click-next)))))

(deftest html5-history-default-prevented-link-click-test
(when browser
(gevents/removeAll js/window goog.events.EventType.POPSTATE)
(gevents/removeAll js/window goog.events.EventType.HASHCHANGE)
(gevents/removeAll js/document goog.events.EventType.CLICK)

(let [history (rfh/start! router (fn [_ _]) {:use-fragment false})
;; Start somewhere else than the link target, so that a handled click
;; would show up as a change of path.
_ (rfh/push-state history ::frontpage)
path-before (rfh/-get-path history)
link (doto (js/document.createElement "A")
(.setAttribute "href" (rfh/href history ::foo))
(.addEventListener "click" (fn [e] (.preventDefault e))))]
(.appendChild js/document.body link)
(.click link)
(is (= path-before (rfh/-get-path history))
"link click is not handled when its default action is prevented")
(.remove link)
(rfh/stop! history))))
Loading