Fork me on GitHub
#reitit
<
2022-06-07
>
geraldodev13:06:04

Hi I'm calling rfe/start! on the top level unit, before the 1st invocation of rfe/href in order to not getting error message due to it's null value. Aftewards on the main component I call rfe/start! again on a hooks/use-effect context. Do you see any problem in that approach ?

geraldodev21:06:29

;; Calling before the first use of rfe/href in order to initialize the routing process and not blow up react
;; because "No protocol method Router.match-by-name defined for type null: " that happens when (rfe/href)
;;  is called without reitit.frontend.easy being globally initialized
(rfe/start!
 (rf/router routes)
 (constantly nil)
 {:use-fragment true})

(defnc LeftMenu
  [{:keys [match]}]
  (d/ul
   (d/li (d/a {:href (rfe/href ::countries)} "Countries"))
   (d/li (d/a {:href (rfe/href ::regions)} "Regions"))))

(defnc RootComponent
  []
  (let [[match set-match] (hooks/use-state nil)
        view (get-in match [:data :view])]
    (hooks/use-effect
     :once
     (rfe/start!
      (rf/router routes)
      (fn [m]
        (set-match m))
      {:use-fragment true}))