mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Fixes based on review
This commit is contained in:
parent
22f38d9992
commit
0919b46236
2 changed files with 14 additions and 12 deletions
|
|
@ -31,8 +31,12 @@
|
|||
(defn Redirect
|
||||
"Component that only causes a redirect side-effect."
|
||||
[props]
|
||||
(redirect! props)
|
||||
nil)
|
||||
(r/create-class
|
||||
{:component-did-mount (fn [this] (redirect! (r/props this)))
|
||||
:component-did-update (fn [this [_ prev-props]]
|
||||
(if (not= (r/props this) prev-props)
|
||||
(redirect! (r/props this))))
|
||||
:render (fn [this] nil)}))
|
||||
|
||||
(defn item-page [match]
|
||||
(let [{:keys [path query]} (:parameters match)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@
|
|||
(re-frame/reg-event-db
|
||||
::navigated
|
||||
(fn [db [_ new-match]]
|
||||
(assoc db :current-route new-match)))
|
||||
(let [old-match (:current-route db)
|
||||
controllers (rfc/apply-controllers (:controllers old-match) new-match)]
|
||||
(assoc db :current-route (assoc new-match :controllers controllers)))))
|
||||
|
||||
;;; Subscriptions ;;;
|
||||
|
||||
|
|
@ -99,11 +101,8 @@
|
|||
:stop (fn [& params] (js/console.log "Leaving sub-page 2"))}]}]])
|
||||
|
||||
(defn on-navigate [new-match]
|
||||
(let [old-match (re-frame/subscribe [::current-route])]
|
||||
(when new-match
|
||||
(let [cs (rfc/apply-controllers (:controllers @old-match) new-match)
|
||||
m (assoc new-match :controllers cs)]
|
||||
(re-frame/dispatch [::navigated m])))))
|
||||
(when new-match
|
||||
(re-frame/dispatch [::navigated new-match])))
|
||||
|
||||
(def router
|
||||
(rf/router
|
||||
|
|
@ -118,16 +117,15 @@
|
|||
{:use-fragment true}))
|
||||
|
||||
(defn nav [{:keys [router current-route]}]
|
||||
(into
|
||||
[:ul]
|
||||
[:ul
|
||||
(for [route-name (r/route-names router)
|
||||
:let [route (r/match-by-name router route-name)
|
||||
text (-> route :data :link-text)]]
|
||||
[:li
|
||||
[:li {:key route-name}
|
||||
(when (= route-name (-> current-route :data :name))
|
||||
"> ")
|
||||
;; Create a normal links that user can click
|
||||
[:a {:href (href route-name)} text]])))
|
||||
[:a {:href (href route-name)} text]])])
|
||||
|
||||
(defn router-component [{:keys [router]}]
|
||||
(let [current-route @(re-frame/subscribe [::current-route])]
|
||||
|
|
|
|||
Loading…
Reference in a new issue