[英]Why is a pound symbol required in my Reitit routes?
I have been making a personal site using ClojureScript and decided to go with Reitit as my routing library instead of my usual Secretary.我一直在使用 ClojureScript 制作个人网站,并决定使用 Reitit 作为我的路由库而不是我通常的秘书 go。 I have read really good things about Reitit and have it sort of working, but it only will react when I navigate to a path with '#' in it.
我已经阅读了关于 Reitit 的非常好的东西,并且它有点工作,但只有当我导航到其中包含“#”的路径时它才会做出反应。
Example: I want to be able to go to "website.com/posts", but it only recognizes when I go to "website.com/#/posts"示例:我希望能够将 go 转至“website.com/posts”,但它仅在我将 go 转至“website.com/#/posts”时识别
My routes.cljs is pretty much a copy of their re-frame example:我的 routes.cljs 几乎是他们重新构建示例的副本:
(defn href
([k]
(href k nil nil))
([k params]
(href k params nil))
([k params query]
(rfe/href k params query)))
(def routes
["/"
[""
{:name :home
:view v/main-panel
:controllers [{:start (fn [& params] (js/console.log "Home"))
:stop (fn [& params] (js/console.log "Leaving Home"))}]}]
["posts"
{:name :posts
:view v/post-panel
:controllers [{:start (fn [& params] (js/console.log "Posts"))
:stop (fn [& params] (js/console.log "Leaving Posts"))}]}]])
(defn on-navigate [new-match]
(when new-match
(re-frame/dispatch [::e/navigated new-match])))
(def router
(rf/router
routes
{:data {:coercion rss/coercion}}))
(defn init-routes! []
(rfe/start!
router
on-navigate
{:use-fragment true}))
and my events.cljs also follows their example:我的 events.cljs 也遵循他们的例子:
(re-frame/reg-event-fx
::navigate
(fn [db [_ & route]]
{::navigate! route}))
(re-frame/reg-event-fx
::navigate!
(fn [route]
(apply rfe/push-state route)))
(re-frame/reg-event-db
::navigated
(fn [db [_ new-match]]
(let [old-match (:page db)
controllers (rfc/apply-controllers (:controllers old-match) new-match)]
(assoc db :page (assoc new-match :controllers controllers)))))
In my views.cljs I have some logic to change what page is displayed based on the dictionary entry:page在我的views.cljs中,我有一些逻辑可以根据字典条目更改显示的页面:page
(defn page []
(let [current @(rf/subscribe [::subs/page])]
[:div {:style {:justify-content :center}}
[navbar]
(case (:name (:data current))
:home [main-panel]
:posts [posts-panel]
[:div])]))
Routing sort of works so I am able to push forward with my website for now but I would love for the final product to not have '#' in the URL when navigating it.路由类型的工作,所以我现在可以推进我的网站,但我希望最终产品在导航时在 URL 中没有“#”。
What am I missing?我错过了什么? Web dev is still pretty new to me so all suggestions are very welcome.
Web 开发人员对我来说仍然很新,所以非常欢迎所有建议。
Try to pass {:use-fragment false}
into rfe/start!
尝试将
{:use-fragment false}
传递给rfe/start!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.