luminus

grischoun 2020-11-23T17:05:58.052Z

Given the following routes: (def router (reitit/router [["/" {:name :home :view #'home-page :controllers [{:start (fn [_] (rf/dispatch [:page/init-home]))}]}] ["/about" {:name :about :view #'about-page}] ["/login" {:name :login :view #'login-page}]])) And the following re-frame definitions: (ns lion.events (:require [re-frame.core :as rf] [ajax.core :as ajax] [reitit.frontend.easy :as rfe] [reitit.frontend.controllers :as rfc])) ;;dispatchers (rf/reg-event-db :common/navigate (fn [db [_ match]] (let [old-match (:common/route db) new-match (assoc match :controllers (rfc/apply-controllers (:controllers old-match) match))] (assoc db :common/route new-match)))) (rf/reg-fx :common/navigate-fx! (fn [[k & [params query]]] (rfe/push-state k params query))) (rf/reg-event-fx :common/navigate! (fn [_ [_ url-key params query]] {:common/navigate-fx! [url-key params query]})) (rf/reg-event-fx :login (fn [_ _] {:http-xhrio {:method :get :uri "/api/login" :headers {:Authorization "Basic xxxxxxx=="} :response-format (ajax/raw-response-format) :on-success [:common/navigate ??????]}})) ;;subscriptions (rf/reg-sub :common/route (fn [db _] (-> db :common/route))) (rf/reg-sub :common/page-id :<- [:common/route] (fn [route _] (-> route :data :name))) (rf/reg-sub :common/page :<- [:common/route] (fn [route _] (-> route :data :view))) Assuming a successful login, what code do I associate with the :on-success in the :login event handler so that I switch to another route, e.g. the /about page? I suspect I should dispatch a :common/navigate event but what would be the argument then?