clj-commons / secretary

A client-side router for ClojureScript.
773 stars 64 forks source link

No dispatch upon page load #88

Open vans163 opened 7 years ago

vans163 commented 7 years ago

First time a page loads there is no dispatch. For example my SPA has a certain component to display if they are on /login, the app determines that by a dispatch on secretary navigate. When you navigate directly to /login secretary fails to trigger the dispatch.

vans163 commented 7 years ago

On second thought this maybe related to Reagent/React.JS in general and orders of events. But I fixed it by using the JS HistoryAPI directly and triggering the first route (after page load) by subscribing to

(js/window.addEventListener "DOMContentLoaded" #())
dchacke commented 4 years ago

I ran into the same issue at first, but was able to fix it by making sure I always dispatch only after the routes have been declared.