我正在尝试在我的应用程序中设置路由,以便:
到目前为止,我的路由代码是:
(defn controller-routes [locale]
(home/c-routes locale)
(search/c-routes locale)))
(defroutes app-routes
(route/resources "/")
(context "/:locale" [locale]
(controller-routes locale))
no-locale-route
(route/not-found "Not Found"))
搜索/ C-路线:
(defn c-routes [locale]
(GET "/search" [] (index locale)))
家/ C-路线:
(defn c-routes [locale]
(GET "/" [] (index locale)))
我无法理解为什么这不能正常工作,但目前“/ uk / search /”匹配正确,但“/ uk /”给出404页面。
任何帮助将不胜感激。感谢。
答案 0 :(得分:4)
controller-routes
是一个正常的函数,它现在返回最后一条路,即搜索,因此只搜索工作。您需要的是使用controller-routes
使defroutes
成为路线并更改c路线:
搜索/ C-路线:
(def c-routes (GET "/search" [locale] (index locale)))
家/ C-路线:
(def c-routes (GET "/" [locale] (index locale)))
使用上述路线的地方:
(defroutes controller-routes
home/c-routes
search/c-routes)
(defroutes app-routes
(route/resources "/")
(context "/:locale" [locale]
controller-routes)
no-locale-route
(route/not-found "Not Found"))