使用compojure
如何设置默认路由,例如
(defroutes app
(GET '/api/user/:id/' [] show-user)
(default-handler render-template)) ; this is what I want
反正有没有实现这个目标?我知道not-found
,但它给了我404 http状态。
答案 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路线从上到下匹配,因此未匹配的任何内容都会回退到您的/
处理程序。