This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-23
Channels
- # announcements (10)
- # babashka (7)
- # beginners (31)
- # boot (4)
- # calva (8)
- # chlorine-clover (19)
- # cider (12)
- # clj-kondo (27)
- # cljsrn (7)
- # clojure (68)
- # clojure-colombia (2)
- # clojure-europe (47)
- # clojure-italy (16)
- # clojure-nl (4)
- # clojure-spec (13)
- # clojure-uk (39)
- # clojurescript (103)
- # code-reviews (8)
- # community-development (2)
- # conjure (38)
- # core-async (37)
- # cursive (2)
- # datascript (1)
- # datomic (31)
- # figwheel-main (22)
- # fulcro (18)
- # jobs (2)
- # jobs-discuss (6)
- # juxt (3)
- # keechma (1)
- # lambdaisland (6)
- # malli (30)
- # meander (20)
- # off-topic (29)
- # reagent (1)
- # reitit (16)
- # shadow-cljs (4)
- # tools-deps (70)
- # xtdb (19)
@orlandomr27 how's your luminus app going? did you get those routes to work?
Hi @plexus, I'm glad you asked. My wiki route is working fine, with some changes. But I could understand how to get :slug
from the :path-params
. This is my code right now for the lambwiki.routes.home
namespace:
(ns lambwiki.routes.home
(:require
[lambwiki.layout :as layout]
[lambwiki.db.core :as db]
[ :as io]
[lambwiki.middleware :as middleware]
[ring.util.response]
[ring.util.http-response :refer [found]]))
(defn home-page [request]
(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
(defn render-wiki-page [request page]
(clojure.pprint/pprint page)
(layout/render request "wiki-page.html" page))
#_(defn about-page [request]
(layout/render request "about.html"))
(defn home-routes []
[""
{:middleware [middleware/wrap-csrf
middleware/wrap-formats]
:conflicting true}
["/" {:get (fn [] (found "/wiki/home"))}]
["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
(when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
(render-wiki-page request page)))}]])
"/wiki:/slug"
route is working if I add the handler home-page
to "/"
, but I'm getting an error with "/"
when I use found "/wiki/home
user> (start)
Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:19).
path "/" doesn't have a :handler defined for :get
{:path "/", :data {:middleware [#function[lambwiki.middleware/wrap-csrf] #function[lambwiki.middleware/wrap-formats]], :conflicting true, :status 302, :headers {"Location" "/home"}, :body ""}, :scope :get}
hmmm not sure, I do think you should add a parameter to (fn [] (found "/wiki/home"))
, like (fn [_req] (found "/wiki/home"))
I made some changes and it stopped complaining.
(defn home-page [request]
(found "/wiki/home")
#_(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
(defn render-wiki-page [request page]
(clojure.pprint/pprint page)
(layout/render request "wiki-page.html" page))
#_(defn about-page [request]
(layout/render request "about.html"))
(defn home-routes []
[""
{:middleware [middleware/wrap-csrf
middleware/wrap-formats]
:conflicting true}
["/" {:get home-page}]
["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
(when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
(render-wiki-page request page)))}]])
Now it is redirecting just as expected!
Thank you! :DNice! Have you watched the ring episodes? They should give a pretty good foundation for this stuff
I watched Ring Part1, the other 5 episodes are on my list 😉 I keep jumping from here and there depending on what I need to know. I guess I have to do it in order to get the explanation on some things I dont understand sometimes.
I made some changes and it stopped complaining.
(defn home-page [request]
(found "/wiki/home")
#_(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
(defn render-wiki-page [request page]
(clojure.pprint/pprint page)
(layout/render request "wiki-page.html" page))
#_(defn about-page [request]
(layout/render request "about.html"))
(defn home-routes []
[""
{:middleware [middleware/wrap-csrf
middleware/wrap-formats]
:conflicting true}
["/" {:get home-page}]
["/wiki/:slug" {:get (fn [{{slug :slug} :path-params :as request}]
(when-let [page (db/find-page-by-uri-slug {:uri_slug slug})]
(render-wiki-page request page)))}]])
Now it is redirecting just as expected!
Thank you! :D