Reputation: 123
I am trying to define some routes to use on my website. I have them defined like so:
(def routes
["/"
[""
{:name :home
:controllers [{:start (fn [& params] (js/console.log "Home"))
:stop (fn [& params] (js/console.log "Leaving Home"))}]}]
["posts"
[""
{:name :posts
:controllers [{:start (fn [& params] (js/console.log "Posts"))
:stop (fn [& params] (js/console.log "Leaving Posts"))}]}]
(for [post blog/posts]
[(:route post)
{:name (:tag post)
:controllers [{:start (fn [& params] (js/console.log (:name post)))
:stop (fn [& params] (js/console.log "Leaving " (:name post)))}]}])]])
(defn on-navigate [new-match]
(when new-match
(re-frame/dispatch [::e/navigated new-match])))
(def router
(rf/router
routes))
(defn init-routes! []
(rfe/start!
router
on-navigate
{:use-fragment false}))
This is supposed to dynamically create routes for the blog posts I define in my blog file. It works great when I start at either localhost:8280/
or localhost:8280/posts
and click the post link that navigates to localhost:8280/posts/blank
(the blog post template page). If I am viewing a post (/posts/blank
) and refresh the page, it opens to a blank screen and doesnt seem to load any of the compiled javascript. If I reload on either /
or /posts
it works as expected and allows me to keep browsing.
I have two questions about Reitit that I would be very grateful for some help on:
/posts
and not /posts/
, how can I register the route with the extra /
on the end as well? If I try to define two routes with the same name Reitit does not allow it.Upvotes: 2
Views: 373