-
Notifications
You must be signed in to change notification settings - Fork 64
History
xpe edited this page Dec 9, 2014
·
2 revisions
This is some code taken from the secretary history example:
;; Quick and dirty history configuration.
(let [h (History.)]
(goog.events/listen h EventType.NAVIGATE #(secretary/dispatch! (.-token %)))
(doto h
(.setEnabled true)))
The first event from goog.History.Event has a token set to ""
. For many applications, it is useful to handle the case differently. You might try this:
(let [h (History.)
f (fn [he] ;; goog.History.Event
(.log js/console "navigate %o" (clj->js he))
(let [token (.-token he)]
(if (seq token) ;; preferred over (not (empty? token))
(secretary/dispatch! token)))))]
(events/listen h EventType/NAVIGATE f)
(doto h (.setEnabled true)))
Another way (perhaps better) is to test isNavigation
. From history.Event:
isNavigation : boolean True if the event was triggered by a browser action, such as forward or back, clicking on a link, editing the URL, or calling window.history.(go|back|forward). False if the token has been changed by a setToken or replaceToken call.