reitit.frontend - HTML5Router does not prevent anchor click as should on matching route

131 views Asked by At
(gevents/listen js/document goog.events.EventType.CLICK ignore-anchor-click))
  • should be - then all works
(gevents/listen js/document goog.events.EventType.CLICK ignore-anchor-click true))

question

  • is there a way to change this behavior without PR or forking?
1

There are 1 answers

0
Sergei-Udris On

solution

  • copy function code from reitit.frontent.history
  • using history ref unsubscribe and resubscribe
(let [history (Yzma.frontend.easy/start! _ _ _)]
  (goog.events/unlistenByKey (:click-listen-key history))
  (goog.events/listen
   js/document
   goog.events.EventType.CLICK
   (fn [event]
     (when-let [element (Yzma.frontend.history/closest-by-tag
                         (Yzma.frontend.history/event-target event) "a")]
       (let [uri (.parse goog.Uri (.-href element))]
         (when (Yzma.frontend.history/ignore-anchor-click?
                (.-router history) event element uri)
           (.preventDefault event)
           (let [path (str (.getPath uri)
                           (when (.hasQuery uri)
                             (str "?" (.getQuery uri)))
                           (when (.hasFragment uri)
                             (str "#" (.getFragment uri))))]
             (.pushState js/window.history nil "" path)
             (Yzma.frontend.history/-on-navigate history path)))))) true))