我正在使用秘书和试剂。这是我的代码:
(def view (atom nil))
(defn layout [view]
[:div @view])
(reagent/render-component [layout view] (.getElementById js/document "message"))
(secretary/set-config! :prefix "")
(secretary/defroute home-path "/" [query-params]
(timbre/info "Path : /, query params : " query-params)
(let [warning (:warning query-params)
success (:success query-params)
login-failed (:login_failed query-params)]
(when warning
(timbre/info "Warning found : " warning)
(reset! view [:h4 [:span.label.label-warning warning]]))
(when success
(timbre/info "Success found : " success)
(reset! view [:h4 [:span.label.label-info success]]))
(when login-failed
(timbre/info "Login failed")
(reset! view [:h4 [:span.label.label-warning "Login Failed."]]))))
(let [h (History.)]
(goog.events/listen h EventType.NAVIGATE #(secretary/dispatch! (.-token %)))
(doto h
(.setEnabled true)))
忽略 :prefix 值(我尝试了“”、“#”并且根本没有设置 :prefix)此代码仅适用于以下路由:
http://localhost:8080/login#/?success=SuccessMessage
但它不适用于以下路线:
http://localhost:8080/login?success=SuccessMessage
我实际上想要实现的是解析来自朋友的登录失败,如果失败将我重定向到
http://localhost:8080/login?&login_failed=Y&username=someUser
并向用户显示登录失败消息。我不需要为此使用秘书,任何可以解析查询参数的东西对我来说都可以。
困难的方法是解析我可以得到的查询字符串:
(-> js/window .-location .-search)
我相信这在某些图书馆已经做得很好了。