1

我正在尝试在我的应用程序中设置路由,以便:

  • /:locale/ -> Home,带有区域绑定
  • /:locale/search -> 搜索,使用语言环境绑定

到目前为止,我的路由代码是:

(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 页面。

任何帮助,将不胜感激。谢谢。

4

1 回答 1

4

controller-routes是一个正常的函数,它现在返回最后一条路线,即搜索,因此只有搜索有效。您需要的是controller-routes使用defroutes和更改 c-routes 来制作路线:

搜索/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"))
于 2013-03-17T16:57:00.553 回答