url::laravel 中的上一问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26992109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
url::previous issue in laravel
提问by Ronser
I have a main list view pageand a product pageand an items page
我有一个主要的list view page和一个product page和一个items page
I have used the URL::previous()in a a href=""tag
我URL::previous()在a href=""标签中使用了
<a class="btn" title="Back" alt="Back" href="{{URL::previous()}}">Back</a>
In my product pageand in items page
在我product page和items page
When I go to products page through list view page and press the back button it goes to the pagged url of the list view page and when I press back button in items page it goes to the product page
当我通过列表视图页面转到产品页面并按后退按钮时,它会转到列表视图页面的分页网址,当我在项目页面中按后退按钮时,它会转到产品页面
But if I press the back button now it again goes to the items page instead of the list view page
但是如果我现在按下后退按钮,它会再次转到项目页面而不是列表视图页面
Is there a way that I could only go back if I am from certain url in laravel?? or is there any functions regarding this...
如果我来自 laravel 中的某个 url,有没有办法让我只能回去?或者是否有任何关于此的功能...
Hope I have explained my problem up to a certain extent.. awaiting for your suggestions regarding this...
希望我已经在一定程度上解释了我的问题......等待你的建议......
回答by Matt Burrow
This is because the URL::previous()uses the HTTP_REFERERwithin the header, meaning the previous page is always the page you were on before.
这是因为在标题中URL::previous()使用了HTTP_REFERER,这意味着上一页始终是您之前所在的页面。
And sometimes the HTTP_REFERERheader does not always exist.
有时HTTP_REFERER标题并不总是存在。
Either define the route you want to go back to using link_to_route()or a url generating method of your choice.
定义您要返回使用的路线link_to_route()或您选择的 url 生成方法。
Or
或者
You could use javascript and use window.history.back()within the onclickattribute of your back button but again, you may not get the intended results.
您可以使用 javascript 并window.history.back()在onclick后退按钮的属性中使用,但同样,您可能无法获得预期的结果。
My solution would be to explicitly define the back route/url.
我的解决方案是明确定义返回路由/url。

