Fork me on GitHub
#re-frame
<
2022-01-31
>
rcaze21:01:03

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 🙂

p-himik21:01:27

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.

rcaze21:01:19

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

steveb8n00:02:09

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}))

steveb8n00:02:02

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

rcaze15:02:09

Got it, thanks