clojurescript base-url / prefix-url in routing using bidi and pushy

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

我正在 clojurescript SPA 中实现路由(使用试剂和重构构建)。对于路由,我使用 bidi 和 pushy。下面是我的路由代码。

(def routes
  ["/" {""            :home-section
        "about"       :about-section
        "contactus"   :contactus-section}])

(def history
  (let [dispatch #(dispatch [::handlers/set-active-page {:page (:handler %)}])
        match    #(bidi/match-route routes %)]
       (pushy/pushy dispatch match)))

(defn start!
      []
      (pushy/start! history))

(def url-for (partial bidi/path-for routes))

来自 core.cljs 我正在呼叫开始!方法。所以当我运行它时它工作正常。例如,

  • localhost:3000 -> 给出正确的主页部分
  • localhost:3000/about -> 显示关于部分
  • localhost:3000/contactus -> 显示联系我们部分 这很好。

但我的要求是我想提供我自己的基本网址,即前缀网址。

  • localhost:3000/myapp -> 应该显示主页
  • localhost:3000/myapp/about -> 显示关于部分
  • localhost:3000/myapp/contactus -> 显示联系我们部分

任何人请建议我如何实现这一目标。这是我在 shadow-cljs.edn 文件中定义的 bidi 和 pushy 依赖项

[bidi "2.1.5"]
[kibu/pushy "0.3.8"]
functional-programming clojure url-routing clojurescript
© www.soinside.com 2019 - 2024. All rights reserved.