mirror of
https://github.com/metosin/reitit.git
synced 2025-12-30 21:28:25 +00:00
Fix FragmentHistory -stop method
This commit is contained in:
parent
b99e25ef4f
commit
d7c025d912
1 changed files with 5 additions and 6 deletions
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
;; This version listens for both pop-state and hash-change for
|
||||
;; compatibility for old browsers not supporting History API.
|
||||
(defrecord FragmentHistory [on-navigate router listen-key last-fragment]
|
||||
(defrecord FragmentHistory [on-navigate router popstate-listener hashchange-listener last-fragment]
|
||||
History
|
||||
(-init [this]
|
||||
;; Link clicks and e.g. back button trigger both events, if fragment is same as previous ignore second event.
|
||||
|
|
@ -30,12 +30,11 @@
|
|||
(-on-navigate this path))))]
|
||||
(-on-navigate this (-get-path this))
|
||||
(assoc this
|
||||
:listen-key (gevents/listen js/window
|
||||
#js [goog.events.EventType.POPSTATE goog.events.EventType.HASHCHANGE]
|
||||
handler
|
||||
false))))
|
||||
:popstate-listener (gevents/listen js/window goog.events.EventType.POPSTATE handler false)
|
||||
:hashchange-listener (gevents/listen js/window goog.events.EventType.HASHCHANGE handler false))))
|
||||
(-stop [this]
|
||||
(gevents/unlistenByKey listen-key))
|
||||
(gevents/unlistenByKey popstate-listener)
|
||||
(gevents/unlistenByKey hashchange-listener))
|
||||
(-on-navigate [this path]
|
||||
(reset! last-fragment path)
|
||||
(on-navigate (rf/match-by-path router path) this))
|
||||
|
|
|
|||
Loading…
Reference in a new issue