如何在网址中使用或不使用结尾斜杠显示页面?

时间:2013-10-08 02:33:48

标签: clojure ring noir

我使用黑色。

拥有:

(defpage "/welcome" [] "Welcome to Noir!")

我是否将这两个URL都设为:

http://localhost:8080/welcome 
http://localhost:8080/welcome/

谢谢!

编辑: 这是完整的答案。

server.clj中,加上(:use [ring.util.response :only [redirect]])

然后写:

(defn wrap-slash 
  ""
  [handler]
  (fn [{:keys [uri] :as req}]
    (if (and (.endsWith uri "/") (not= uri "/"))
      (handler (assoc req :uri (.substring uri
                                0 (dec (count uri)))))
      (handler req))))

(server/add-middleware wrap-slash)

1 个答案:

答案 0 :(得分:1)

Noir的路由比其他路由更严格,所以看看this question,虽然有不同的标题,但也会问同样的事情。

相关问题