I have an action in an Compojure/Luminus app:
(defn my-page1 [id]
(layout/render "my_page.html"
(let
[item (db/get-single-item {:id id})]
; this throws an exception
; if .....
; redirect "fdsfdsfd" :status 301
{ :my-item item})))
How can I check some condition and if it's true, then do a redirect to a new url with the http status 301? Where should I put in the my code and how can I do a redirect?
Your layout/render
function returns a full HTTP 200 ring response with HTML body content. You need to return a redirect response instead of the response produced by layout/render
function:
(defn my-page1 [id]
(if (some-condition)
(layout/render ...)
(ring.util.response/redirect "http://elsewhere.com/" 301)))