我正在尝试使用试剂来构建我非常基本的项目,但是路由及其参数存在问题。这是来自试剂的样子
已编辑- :require 已添加
(ns hammerslider.core
(:require [reagent.core :as reagent :refer [atom]]
[secretary.core :as secretary :include-macros true]
[accountant.core :as accountant]))
;; Views
(defn home-page []
[:div [:h2 "Welcome to hammerslider"]
[:div [:a {:href "/c/12"} "go custom"]]])
(defn c [test]
[:div [:h2 (str "on C " test)]
[:div [:a {:href "/"} "go to the home page"]]])
我正在尝试12
从c
路线获取路线处理看起来像这样
(def page (atom #'home-page))
(defn current-page []
[:div [@page]])
(secretary/defroute "/" []
(reset! page #'home-page))
(secretary/defroute "/c/:test" [test]
(reset! page #'c)
我试图test
用视图函数捕捉参数,但它出现了on C
,而不是on C 12
。如何将test
参数传输到视图中c
?还是我应该把它保存在不同的地方atoms
?
已编辑- 我通过将参数保存到 atom 中解决了它并且它可以工作,但它是传递参数的正确方法吗?
(def parameter (atom ()))
(defn c []
[:div [:h2 (str "on C " (:test @parameter))]
[:div [:a {:href "/"} "go to the home page"]]])
(secretary/defroute "/c/:test" {:as params}
(do (js/console.log params)
(reset! parameter params)
(reset! page #'c)
))