Выяснил, как извлечь параметры пути из запроса на получение Reitit на бэкэнде в routes.clj
. Пришлось извлечь ключ path-params из запроса, а затем получить из него идентификатор. Теперь можно правильно анализировать параметры пути, что означает, что обновление страницы больше не приводит к ошибке 404.
TL; DR
(ns project-name.routes
(:require [ring.util.http-response :as http-response]))
(defn admin-routes
"The basic routes to be handled by the SPA (as rendered by fn `admin-page`)"
[]
["" {:middleware [middleware/wrap-base
middleware/wrap-formats]}
["/admin"
["/edit-job/:id"
{:get (fn [{:keys [path-params] :as _req}]
(http-response/ok
(core/READ :jobs (Integer/valueOf (:id path-params)))))}]]])
Документация и примеры, полученные из https://github.com/luminus-framework/luminus-docs/blob/master/resources/md/sessions_cookies.md . Контроллеры использовались, как задокументировано https://clojureverse.org/t/how-do-you-accomplish-spa-re-frame-teardown/5516/6.
Внешняя маршрутизация в routes.cljs
(ns humhelp.routes
(:require [re-frame.core :as rfc]
[reitit.frontend :as rf]
[reitit.frontend.easy :as rfe]))
(defn request-entry
"if an id is present in the url, this function will make a get request to retrieve the entry in the appropriate table"
[path url table-keyword]
(let [ submit-params
{:uri (str url (-> path :path :id) )
:on-success-kvec
[:set-currently-selected table-keyword]}]
(rfc/dispatch [:handler-with-http submit-params])))
(def routes
(rf/router
["/"
["edit-job/:id"
{:name ::edit-job
:view #'confirm-job-modification-modal/edit-job
:controllers [{:parameters {:path [:id]}
:start (fn [path]
(request-entry path "/admin/edit-job/" :jobs))
:stop (fn [_] (do
(println "Running stop!")
(rfc/dispatch [:set-currently-selected :jobs nil])))}]}]))
(defn init-routes!
"Start the routing"
[]
(rfe/start! routes
(fn [m]
(rfc/dispatch [:set-current-page m]))
{:use-fragment false}))
events.cljs
(ns humhelp.events
(:require
[re-frame.core :refer [reg-event-db after reg-event-fx dispatch] :as rfc]
[project-name.views.dashboard :as dash]
[ajax.core :as ajax]
[project-name.db :as db :refer [app-db]]
[clojure.spec.alpha :as s]
[reitit.frontend.controllers :as rfcontrol]))
(rfc/reg-event-fx
:handler-with-http
(fn handler-with-http [db [_ {:keys [uri params on-success-kvec]}]]
{:http-xhrio {:method :get
:uri uri
; :headers {"Access-Control-Allow-Origin" "http://localhost:3000"}
:params params
:timeout 8000
:response-format (ajax/json-response-format {:keywords? true})
:on-success on-success-kvec
:on-failure [:on-failure]}}))
(rfc/reg-event-db
:set-current-page
(validate-spec ::db/current-page)
(fn [db [_ m]]
(let [prev-match (:current-page db)
controlled (assoc m :controllers (rfcontrol/apply-controllers (:controllers prev-match) m)) ]
(assoc db :current-page controlled))))
(rfc/reg-event-db
:on-success
(validate-spec ::db/api-result)
(fn on-success [db [_ result]]
(assoc db :api-result result)))
routes.home.clj
(def ^{:private true} home-paths [ "/"
"/edit-job/:id"])
(defn home-routes
"The basic routes to be handled by the SPA (as rendered by fn `home-page`)"
[]
(into [""
{:middleware [middleware/wrap-base
middleware/wrap-formats]}]
(into []
(for [route home-paths]
[route {:get home-page}]))))