Is frontend Clojure development the best frontend development eco-system

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at:

I have not done much frontend work these last 3 years, so I am out of touch, but wow, there is a lot going on:

The first step is to define the routes we want. One of the designing features of bidi is that routes are data structures, not function/macro calls:

(def routes ["/" {"" :home
"about" :about}])

The app-routes function that used to define functions is replaced by one that sets up

(defn app-routes []
(pushy/start! (pushy/pushy dispatch-route parse-url)))

parse-url is a very simple function that uses bidi/match-route to turn a URL into a data structure representing it:

(defn- parse-url [url]
(bidi/match-route routes url))

Then dispatch-route is called with that structure:

(defn- dispatch-route [matched-route]
(let [panel-name (keyword (str (name (:handler matched-route)) "-panel"))]
(re-frame/dispatch [:set-active-panel panel-name])))

The :handler of the matched-route will be :home or :about and panel-name is constructed to be :home-panel or :about-panel so that we can dispatch setting the active panel the same way secretary used to do it. And that’s the core of it. You now have to change URLs in the view to be /about and / instead of /#/about and /#/ respectively.

Generating URLs

The whole point of using bidi was to not hard-code the URLs, for that I added this function to routes.cljs:

(def url-for (partial bidi/path-for routes))

which allowed me to replace the previous URLs with:

(routes/url-for :about)


(routes/url-for :home)

This works fine until you try to re-load the about page and you get a 404 Not Found error. This is because the server doesn’t know about the /about URL or any other URL the client-side might support. What you need to do is just send serve the application no matter what the URL and let the client do the dispatching (with any exceptions you might have for APIs and whatnot).