Redirect 如何在Compojure/Luminus应用程序中重定向301 http?

Redirect 如何在Compojure/Luminus应用程序中重定向301 http?,redirect,clojure,compojure,ring,luminus,Redirect,Clojure,Compojure,Ring,Luminus,我在Compojure/Luminus应用程序中有一个操作: (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

我在Compojure/Luminus应用程序中有一个操作:

(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})))
我如何检查一些条件,如果它是真的,然后重定向到http状态为301的新url? 我应该把我的代码放在哪里,如何重定向?

布局/渲染函数返回一个完整的HTTP 200环响应,其中包含HTML正文内容。您需要返回重定向响应,而不是布局/渲染函数生成的响应:

(defn my-page1 [id]
  (if (some-condition)
    (layout/render ...)
    (ring.util.response/redirect "http://elsewhere.com/" 301)))
get single item在找不到项或返回nil时引发异常?