导航并使用后退按钮后,Laravel 5 Flash消息再次闪烁 [英] Laravel 5 flash message flashes again after navigating away and using back button

查看:72
本文介绍了导航并使用后退按钮后,Laravel 5 Flash消息再次闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我试图通过laravel 5中的Flash消息重定向回去.这一切都很好.问题是无论我如何设置,如果我走开然后使用浏览器的后退按钮"返回时,总是会再次显示Flash消息.

In my controller im trying to redirect back with a Flash message in laravel 5. This all works great. The problem is no matter how i set it up the flash message always re-appears if i navigate away and then come back by using the browsers 'back button'.

所以我有一个用户列表,每个用户旁边都有一个删除按钮.当我单击删除按钮时,它将调用我的控制器方法进行销毁.我在其中设置了一些条件,如果我要删除所有者,则会重定向并返回错误.我尝试了以下不同的重定向方法,但所有这些都出现了相同的问题,即在浏览并通过浏览器的后退按钮"返回后,消息再次显示.

So i have a users list with a delete button next to each user. When i click the delete button it calls my controller method to destroy. I made a little conditional in there that redirects back with an error if i am trying to delete an owner. I tried the following different ways to redirect back but with all i wind up with the same problem that the message shows again after navigating away and coming back via the browsers 'back button'.

1

return Redirect::route('users')->with('error_message', 'Some error msg');

2

Session::flash('error_message', 'Some error msg');
return Redirect::to('users'); 

在我看来,我是这样捡起来的:

In my view i pick it up like this:

@if (Session::has('error_message'))
     {{ Session::get('error_message') }}
@endif

所以效果很好,我收到了消息.但是,例如,一旦我在用户列表中单击某个用户以转到详细信息页面,然后按浏览器的后退按钮",该消息就会再次闪烁.我不明白为什么它会不断刷新数据,我的印象是它只刷新一次.

So that works good, i get the message. But as soon as for example i click a user in my user list to go to the details page and press the browser 'back button', the message flashes again. I dont get why it keeps flashing that data, i was under the impression that it just flashes one time.

即使我尝试在显示后立即清除它(如下所示),也没关系,它会一直重新出现吗?

Even if i try to clear it right after displaying (like below), it doesnt matter, it will always re-appear?

{!! Session::forget('error_message') !!}

推荐答案

通常,当用户单击浏览器中的后退"按钮时,浏览器会尝试显示前一页的内容而不重新加载它.因此,Laravel可能不会再次闪烁到会话,而是浏览器尝试通过为您缓存页面来帮助您.

Generally, when the user clicks the back button in the browser, the browser tries to display the contents of the previous page without reloading it. So it's likely not Laravel flashing to the session again, but the browser trying to help you out by caching the page for you.

这篇关于导航并使用后退按钮后,Laravel 5 Flash消息再次闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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