[英]How to redirect back to a route in Sinatra?
In Sinatra, how to redirect back to a route? 在Sinatra中,如何重定向回路线?
require 'sinatra'
get "/A" do
redirect '/B'
end
get "/B" do
redirect request.referer
end
This is the code, and I want "/B" bring me back to "/A". 这是代码,我希望“ / B”使我回到“ / A”。
Now, in browser, in "/C", send a get request to "/A". 现在,在浏览器的“ / C”中,将获取请求发送到“ / A”。 I will then go back to "/C".
然后,我将回到“ / C”。 The reason is:
原因是:
The "request.referer" is recording "/C", because the redirect in "/A" is initiated by the server, it doesn't count as the referrer to the target page. “ request.referer”正在记录“ / C”,因为“ / A”中的重定向是由服务器启动的,因此它不算作目标页面的引荐来源。
There is a JavaScript way solving it(placed on /A): 有一种JavaScript解决方法(位于/ A上):
<script type="text/javascript">window.location = '/B';</script>
(Got this from: How to redirect web page from a specfic page in Sinatra? ) (此内容来自: 如何从Sinatra中的特定页面重定向网页? )
My question is how to redirect back to a route in server side? 我的问题是如何重定向回服务器端的路由?
Just say redirect back
. 只是说
redirect back
。 From the Sinatra README (scroll down to "Browser Redirect"): 从Sinatra自述文件 (向下滚动到“浏览器重定向”):
You can also easily redirect back to the page the user came from with redirect back: 您还可以通过重定向回轻松地重定向到用户来自的页面:
get '/foo' do
"<a href='/bar'>do something</a>"
end
get '/bar' do
do_something
redirect back
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.