简体   繁体   English

为什么我的 Reitit 路线需要英镑符号?

[英]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.

相关问题 在CakePHP中,路由URL包含井号 - Routing URL's containing a pound symbol in CakePHP 让ASP.NET MVC正确地转义路由中的#(hash / pound)字符 - Getting ASP.NET MVC to correctly escape the # (hash/pound) character in routes 骨架.js-具有必需查询的路由 - backbone.js - routes with required query 为什么Rails编码斜杠可捕获所有(splat)路线? - Why is Rails encoding slashes for catch all (splat) routes? 为什么在asp.net mvc中先映射特殊路由,然后再映射普通路由? - Why map special routes first before common routes in asp.net mvc? 如何更改路由中的cakePHP URL? - How do I change my cakePHP urls in routes? 是否有技术原因将Express路由定义为前导斜杠? - Is there a technical reason why Express routes are defined with a leading forward slash? 有没有更好的方法来区分路线中的字符串ID参数和动作名称? - Is there a better way to distinguish between string id parameters and action names in my routes? 我的某些Laravel路由(PUT和DELETE)在共享主机上不起作用 - Some of my Laravel routes (PUT and DELETE) doesn't work on a shared hosting 如何为默认控制器上的重点页面设置Laravel 3路由? - How can I setup Laravel 3 routes for pages of focus on my default controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM