(ns ...
(:require [ring.util.response :refer [ response redirect]))
我的原始代码是相似的
(-> (response "You are now logged in! communist party time!")
(assoc :session new-session)
(assoc :headers {"Content-Type" "text/html"}))
效果很好,但用户仍然需要手动导航到其他地方。
尝试使用 http://ring-clojure.github.io/ring/ring.util.response.html#var-redirect
(-> (redirect requri)
(assoc :session new-session)
(assoc :headers {"Content-Type" "text/html"}))
不执行任何操作(除了返回空白页)。
如何使用环实现到已知 uri 的重定向?
最佳答案
response
是返回一个正文。
你的代码是(response requri)
,但是函数reponse
的参数是html body,而不是uri,你可以使用this function
像这样
(ns foo
(:require [ring.util.response :as response]))
(def requi "/")
(-> (response/redirect requri)
(assoc :session new-session)
(assoc :headers {"Content-Type" "text/html"}))
ps:如果你正在写一个网站。lib-noir是控制 session 等的好方法。
关于redirect - 登录后环重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28910164/