This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-06
Channels
- # aleph (1)
- # beginners (180)
- # calva (16)
- # cider (29)
- # clj-kondo (47)
- # cljsrn (5)
- # clojure (40)
- # clojure-dev (39)
- # clojure-europe (1)
- # clojure-italy (25)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (8)
- # clojure-uk (83)
- # clojurescript (54)
- # core-async (2)
- # datomic (20)
- # defnpodcast (7)
- # figwheel (6)
- # fulcro (6)
- # jobs (5)
- # joker (4)
- # kaocha (4)
- # luminus (4)
- # off-topic (8)
- # onyx (6)
- # pathom (14)
- # re-frame (28)
- # reagent (30)
- # remote-jobs (2)
- # shadow-cljs (88)
- # spacemacs (2)
- # specter (17)
- # sql (25)
- # tools-deps (78)
- # xtdb (1)
- # yada (2)
Hey everyone, I need some help. I'm using https://github.com/oconn/re-frame-routing by @oconn and I'm trying to improve my current routing. My current goal is to have a dynamic URL that I don't have to hard code - I want to do things when the user visits /forum/page-2
or /post/somepostid123
. On my back end, I am using compojure and that allows routes that look like this: (c/GET "/forum/page-:page" [page] (validate page db/get-forum-page))
, and I was wondering if there was anything like this for CLJS with re-frame routing so what I can show different pages depending on the URL without writing them in advance.
Here's what I have so far with regards to routing:
;; Determine what URLs match to what view
(def routes
["/" {"" :forum
"forum" :forum
"tags" :tags
"members" :members
"admin" :admin}])
;; Import routing events
(rfr/register-events {:routes routes})
;; Choose which component function to use depending on route
(defmulti get-page-content identity)
(defmethod get-page-content :forum [] forum/forum)
(defmethod get-page-content :tags [] tags)
(defmethod get-page-content :members [] members)
(defmethod get-page-content :admin [] admin)
(defmethod get-page-content :default [] not-found)
Thank you in advance for your help! I'm going to go for a shower quickly but I'll be back in a couple of minutes!You can do something like
(def routes
["/" {"" :forum
"forum" :forum
"tags" :tags
"members" :members
"admin" :admin
"posts" :posts
["posts/" :post-id] :post}])
@ashley It’s built ontop of https://github.com/juxt/bidi - so you’ll want to reference their docs for constructing routes.
ohhhh thank you!!
@oconn thank you for your help, I got it working. One thing I am struggling though, is that pagination doesn't seem to actually change the look of the page.
(def routes
["/" {"" :forum
"forum/" { "" :forum
["page-" [#"\d+" :page-number]] :forum}
....
(defmulti get-page-content identity)
(defmethod get-page-content :forum [] forum/forum)
...
Having a tag href to (str "/forum/page-" p)
doesn't change the view of the page, is it because they're all using the same forum
route? I tested it by separating the /
and /forum/
from /forum/page-n
and introduced :forum-page
, but this didn't seem to do anything either. Any ideas?It does indeed
But its weird as using a
tags like normal works usually, its just the pagination links I have (presumably because its going from :forum
to :forum
?
Sure. Let me make a gist
So route.cljs is the first port of call
routed-page
combines common elements like the navbar, footer, notifiations and finally the dynamic body as selected by get-page-content
.
forum
gets selected by get-page-content
and draws everything specific to the forum browsing pages
Thank you for all of your help by the way!
So my guess is that f/dispatch-fetch-posts
is only called once for your first page load. If there is no logic that re-mounts this view then on nav there will be no change I believe. If you move {:keys [route-key path-params query-params]}
into the function params on line 7
and log path-params
on line 8
and also on line 6
you will probably see two logs printed on initial render and one log line 8
on page navigation.
that would make sense - if the db
isn't being changed, then there'd be no reason to redraw
You nailed it
thank you so much
I need to remember how these views work sometimes
re-frame gives you state management - reagent (react wrapper) is your view layer which does support animations.
I use react-transition-group but you can probably try something like https://github.com/timothypratley/reanimated
Hello! Can someone help? I have some problems with https://github.com/Day8/re-frame-async-flow-fx , can it used in cljc files?