如何设置默认路由?

时间:2014-03-04 03:55:01

标签: clojure

使用compojure如何设置默认路由,例如

(defroutes app
  (GET '/api/user/:id/' [] show-user)
  (default-handler render-template)) ; this is what I want

反正有没有实现这个目标?我知道not-found,但它给了我404 http状态。

1 个答案:

答案 0 :(得分:5)

您只需将处理程序设置为/

即可
(defroutes app
  (GET "/api/user/:id/" [] show-user)
  (GET "/" render-template))

或者如果您想要默认任何HTTP动词:

(defroutes app
  (GET "/api/user/:id/" [] show-user)
  (ANY "/" render-template))

Compojure路线从上到下匹配,因此未匹配的任何内容都会回退到您的/处理程序。