I think this solution hits a snag when you have nested navigators, and you want the action to be dispatched against a child navigator - usually the parent of the screen where you're dispatching the event to effect the navigation. What I ended up doing recently was using the navigator ref as you're doing here to persist nav state for reloads, but wrapping the event dispatch function to add the navigation prop (from useNavigation
) to the event as metadata. Then the effect handler uses that to dispatch the navigation action, rather than the root navigator in the ref.
looks like some earlier messages in this thread were archived already, so apologies if my response is missing some important context 🙂
Hi Anson. I found nested navigators fiddly but doable.
; event handler
(rf/reg-event-fx :home-my-map-press
[]
{:dispatch [:setup-route :app.screens/my-map]
:navigate2 ["TabStack" {:screen "MapStack"}]})
; fx
(rf/reg-fx :navigate2 (fn [[a b]] (navigation/navigate2 a b)))
; helper
(defn navigate2 [a b] (.navigate @*navigator a (clj->js b)))