登录后重定向

sov*_*ova 5 redirect clojure ring

(ns ...
  (:require  [ring.util.response :refer [ response redirect]))
Run Code Online (Sandbox Code Playgroud)

我的原始代码完全像

(-> (response "You are now logged in! communist party time!")
    (assoc :session new-session)
    (assoc :headers {"Content-Type" "text/html"}))
Run Code Online (Sandbox Code Playgroud)

哪个效果很好,但用户仍然需要手动导航到其他地方.

尝试使用http://ring-clojure.github.io/ring/ring.util.response.html#var-redirect

(-> (redirect requri)
    (assoc :session new-session)
    (assoc :headers {"Content-Type" "text/html"}))
Run Code Online (Sandbox Code Playgroud)

什么都不做(除了返回空白页).

如何使用环实现重定向到已知的uri?

ipa*_*ian 6

response是一个身体.你的代码是(response requri),但功能的参数reponse是html体,而不是uri,你可以使用这个函数

像这样

(ns foo
   (:require [ring.util.response :as response]))
(def requi "/")
(-> (response/redirect requri)
    (assoc :session new-session)
    (assoc :headers {"Content-Type" "text/html"}))
Run Code Online (Sandbox Code Playgroud)

ps:如果你正在写一个网站.lib -noir是控制会话和其他的好方法.