我的routes.cljs
文件中定义了应用程序路由,位于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
它被初始化为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))
它被发送::events/set-active-panel
到events.cljs
(re-frame/reg-event-db
::set-active-panel
(fn-traced [db [_ active-panel]]
(assoc db :active-panel active-panel)))
并且:active-panel
订阅了subs.cljs
(re-frame/reg-sub
::active-panel
(fn [db _]
(:active-panel db)))
我订阅:active-panel
了我的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
是nil
我第一次访问页面的时候。仅当我浏览页面时才调度面板。我知道这最初是有效的。我在我的提交中看不到任何可能破坏它的东西。
如何让我defroutes
在页面加载以及通过网站导航时触发?