url::previous issue in laravel

徘徊边缘 提交于 2019-12-12 12:32:32

问题


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

I have used the URL::previous() in a a href="" tag

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

In my product page and in 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...

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


回答1:


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.

And sometimes the HTTP_REFERER header does not always exist.

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

Or

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.



来源:https://stackoverflow.com/questions/26992109/urlprevious-issue-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!