无法使用比迪烟正确路由

问题描述 投票:0回答:1

我正在“ / this-route”上发送索引处理程序:

(defn index-handler [req]
  (assoc (resource-response "index.html" {:root "public"})
         :headers {"Content-Type" "text/html; charset=UTF-8"}))

(def routes ["" {"/this-route" {:get index-handler}}]) ;; works

哪个工作正常。

但是当我向此路由添加任何内容时,即使我仍然可以发送基本的响应/响应,我也无法发送索引处理程序:


(def routes ["" {"/this-route" {"" {:get index-handler} ;; doesn't work
                                "/something" {:get index-handler} ;; doesn't work
                                "/something-else" (res/response "some response") ;; works  

}}])

我在客户端控制台中看到错误,在我启动应用程序的index.html行中显示错误:

    <script type="text/javascript">myapp.system.go();</script>

错误是“未定义myapp。”

为什么会这样,我在做什么错呢?

-编辑-这是控制台中的完整错误:

Uncaught ReferenceError: myapp is not defined
    at something-else:15

DevTools failed to load SourceMap: Could not load content for chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/include.preload.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
clojure clojurescript bidi
1个回答
0
投票

您的路线正常:

  (let [routes ["" {"/this-route" {:get :some-handler}}]]
    (is= (bidi/match-route routes "/this-route" :request-method :get)
      {:handler :some-handler, :request-method :get}))

  (let [routes ["" {"/this-route" {""                {:get :handler-1}
                                   "/something"      {:get :handler-2}
                                   "/something-else" {:get :handler-3}}}]]
    (is= (bidi/match-route routes "/this-route" :request-method :get)
      {:handler :handler-1, :request-method :get})
    (is= (bidi/match-route routes "/this-route/something" :request-method :get)
      {:handler :handler-2, :request-method :get})
    (is= (bidi/match-route routes "/this-route/something-else" :request-method :get)
      {:handler :handler-3, :request-method :get}))

如cfrick所说,您在某种程度上创建了编译和/或加载代码的问题。那是您需要看的地方。

© www.soinside.com 2019 - 2024. All rights reserved.