Fork me on GitHub

Hi, I'm trying to tie re-frame with reitit. I'm wondering what is the correct pattern when trying to navigate to a route like /item/:id to display a dedicated view of a single item (where that item is then fetched via an API call). If I used reitit on backend, I'd just use "/item/:id" as my route and call the controller with a parameter, and render a page. I've looked at the frontend-re-frame example but it doesn't do what I need and I'm having trouble imagining how this should work together. Would appreciate any pointers 🙂


Views should not care about the routes at all. The should care about the data in your app-db, which they get via subscriptions. Navigating to a new route should dispatch some event(s) that end up changing app-db. The views will then simply react to the new data. You might want take a look at kee-frame BTW - it does a few things for you, quite handy.


That makes sense, thanks. Kind of what I imagined, though I still need to think how exactly to implement this.


you want an event listener from rfe to dispatch an event when the history changes. like this

(defn start-router!
  (rfe/start! (rtf/router routes/generated)
              (fn [route-data] (rf/dispatch [:set-route route-data]))
              {:use-fragment true}))


the event updates the db. the root view uses subs to look at the route and decide which sub-view (1 for each route) to display


Got it, thanks