Skip to content

Question: clicking on links does not trigger dispatch? #70

@mac01021

Description

@mac01021

This is probably PEBCAK.
I have the following tiny application using secretary and reagent. Calls to secretary/dispatch! like the one at the bottom of the file update the application as expected. Clicking on the links, however, does not result in a call to dispatch.
Any pointers you can provide will be appreciated. Thanks in advance!

(ns askit-client.main
    (:require [reagent.core :as reagent]
              [secretary.core :as secretary :refer-macros [defroute]]))

(enable-console-print!)


;; Define reagent components
(defn home []
    [:div [:h1 "Welcome, friend!"]
        [:div [:a {:href "#/about"} "about us"]]])
(defn about []
    [:div "Now you know all about us!"
        [:div [:a {:href "#/"} "go home"]]])
(defn current-page [] [(@app-state :current-page)])




;; Set up application state
(def app-state (reagent/atom {}))

(defn put! [k v] (swap! app-state assoc k v))

(put! :current-page home)



;; Define secretary routes
(secretary/set-config! :prefix "#")
(defroute "/" []
    (println "time to go home")
    (put! :current-page home))
(defroute "/about" []
    (println "time to go about")
    (put! :current-page about))



(println "Let's mount this thing and go home!")
(reagent/render-component [current-page] (.getElementById js/document "app"))

(secretary/dispatch! "/about")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions