@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]
[<http://clojure.java.io|clojure.java.io> :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"))
Nice! 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.