laravel中的url :: previous问题 [英] url::previous issue in laravel

查看:78
本文介绍了laravel中的url :: previous问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主list view page和一个product page和一个items page

I have a main list view page and a product page and an items page

我在a href=""标记中使用了URL::previous()

<a class="btn" title="Back" alt="Back" href="{{URL::previous()}}">Back</a>  

在我的product pageitems 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

有没有一种方法,如果我来自laravel中的某些网址,我只能回去吗?或是否有与此相关的功能...

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...

希望我已经在一定程度上解释了我的问题..等待您对此的建议...

Hope I have explained my problem up to a certain extent.. awaiting for your suggestions regarding this...

推荐答案

这是因为URL::previous()使用标头中的HTTP_REFERER,这意味着上一页始终是您之前所在的页面.

This is because the URL::previous() uses the HTTP_REFERER within the header, meaning the previous page is always the page you were on before.

有时HTTP_REFERER标头并不总是存在.

And sometimes the HTTP_REFERER header does not always exist.

使用link_to_route()或您选择的网址生成方法来定义要返回的路线.

Either define the route you want to go back to using link_to_route() or a url generating method of your choice.

您可以使用javascript并在返回按钮的onclick属性内使用window.history.back(),但是同样,您可能无法获得预期的结果.

You could use javascript and use window.history.back() within the onclick attribute of your back button but again, you may not get the intended results.

我的解决方案是明确定义反向路由/网址.

My solution would be to explicitly define the back route/url.

这篇关于laravel中的url :: previous问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆