【问题标题】:Combining routes in Compojure在 Compojure 中组合路线
【发布时间】:2012-01-09 21:06:30
【问题描述】:

我在 Clojure 中使用 Compojure 开发了两个不同的 Web 应用程序。每个都使用 defroutes 来创建它的处理程序。

如何将defroutes的两种不同定义组合成一个defroute?我想将第一个应用程序的路由重用到第二个应用程序中。

【问题讨论】:

    标签: clojure compojure


    【解决方案1】:

    你可以使用compojure.core/routes来组合路由:

     (def my-handler
        (routes some-handler
                some-other-handler))
    

    【讨论】:

    • 我试过 (def route1 [(GET "/" [] (index-page)) (route/resources "/") (route/not-found "Page not found")]) ( def allroutes (concat routes1 routes2)) (def app (handler/site (apply routes allroutes))) 但是第二个路由没有用到
    • 好的,我发现了错误:需要注意第一个列表中没有 route-not-found 处理程序...
    • “好的,我发现了错误:需要注意第一个列表中没有 route-not-found 处理程序... –”请详细说明?您发现了什么解决方案?
    • 也许有点晚了,但我认为重点是 not-found 路由应该在路由列表中的最后一个,否则它将匹配所有 url 并且应用程序将始终返回“未找到” "
    猜你喜欢
    • 1970-01-01
    • 2015-12-14
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 2012-05-31
    • 2011-03-30
    • 2013-04-20
    相关资源
    最近更新 更多