I have application routes defined in my routes.cljs
file in the root of src/cljs/project/routes.cljs
.
(defn app-routes []
(secretary/set-config! :prefix "#")
(defroute
"/" []
(re-frame/dispatch [::events/set-active-panel :welcome-panel])))
; shortened for brevity
It is initialized in core.cljs
; required [portfolio-app.events :as events]
(defn ^:export init []
(routes/app-routes)
(re-frame/dispatch-sync [::events/initialize-db])
(dev-setup)
(mount-root))
It is dispatched to the ::events/set-active-panel
in events.cljs
(re-frame/reg-event-db
::set-active-panel
(fn-traced [db [_ active-panel]]
(assoc db :active-panel active-panel)))
And has the :active-panel
subscription in subs.cljs
(re-frame/reg-sub
::active-panel
(fn [db _]
(:active-panel db)))
I subscribe to :active-panel
in my layout.cljs
; required [portfolio-app.subs :as subs]
(defn panel []
(let [active-panel (re-frame/subscribe [::subs/active-panel])]
[:div
"which panel? " @active-panel]))
@active-panel
is nil
when I access a page for the first time. The panel is dispatched only when I navigate through the pages. I know this worked initially. I can't see anything in my commits that could have broken it.
How do I get my defroutes
to fire on page load as well as through site navigation?