使用默认试剂模板创建的路线如下所示:
;; -------------------------
;; Routes
(def router
(reitit/router
[["/" :index]
["/items"
["" :items]
["/:item-id" :item]]
["/about" :about]]))如果我更改了其中一个的路径(下面的“/about”改为"/test“),为什么它不再起作用?一定有别的什么东西在驱动这条路线,但我似乎想不出是什么。
;; -------------------------
;; Routes
(def router
(reitit/router
[["/" :index]
["/items"
["" :items]
["/:item-id" :item]]
["/test" :about]]))

这是默认的试剂模板(lein new试剂...)并且我没有在代码中更改任何其他内容。任何帮助都将不胜感激。
Edit -我在此函数的repl中查看了一些额外的细节(来自默认模板):
(defn init! []
(clerk/initialize!)
(accountant/configure-navigation!
{:nav-handler
(fn [path]
(let [match (reitit/match-by-path router path)
current-page (:name (:data match))
route-params (:path-params match)]
(reagent/after-render clerk/after-render!)
(session/put! :route {:current-page (page-for current-page)
:route-params route-params})
(clerk/navigate-page! path)
))
:path-exists?
(fn [path]
(boolean (reitit/match-by-path router path)))})
(accountant/dispatch-current!)
(mount-root))在我看来一切都很好。实际上,在repl中执行以下步骤可以成功地将浏览器导航到正确的页面。不过,我仍然不能直接输入URL。
app:problem.core=> (require '[reitit.frontend :as reitit])
nil
app:problem.core=> (reitit/match-by-path router "/test")
{:template "/test",
:data {:name :about},
:result nil,
:path-params {},
:path "/test",
:query-params {},
:parameters {:path {}, :query {}}}
app:problem.core=> (def match (reitit/match-by-path router "/test"))
#'problem.core/match
app:problem.core=> (:name (:data match))
:about
app:problem.core=> (:path-params match)
{}
app:problem.core=> (def current-page (:name (:data match)))
#'problem.core/current-page
app:problem.core=> (page-for current-page)
#'problem.core/about-page
app:problem.core=> (session/put! :route {:current-page (page-for current-page) :route-params {}})
{:route {:current-page #'problem.core/about-page, :route-params {}}}
app:problem.core=>发布于 2020-08-01 23:39:17
看起来您在src/cljs/<project_name>/core.cljs中更改了客户端的路由,但在src/clj/<project_name>/handler.clj中没有更改服务器端的路由(请查看文件底部附近的def app )。
如果您刚开始使用Clojure开发web应用程序,我建议您查看Luminus,而不是使用Reagent模板。这是一种包含更多电池的方法,有更多的文档。“使用Clojure进行Web开发”这本书的作者是同一个人(他也是Reagent的贡献者),也是推荐的读物。
https://stackoverflow.com/questions/63195227
复制相似问题