1
我想阻止用戶點擊瀏覽器按鈕。無論何時用戶登錄並點擊瀏覽器的後退按鈕,頁面將重定向回登錄,這是錯誤的。我創建中間件並將其註冊到內核,並將其作爲組在我的路由中使用,但不工作。下面的代碼Laravel 5.3 - 在中間不能正常工作的地方設置清除緩存
中間件
<?php
namespace App\Http\Middleware;
use Closure;
class ClearCache
{
public function handle($request, Closure $next)
{
$response = $next($request);
$response->headers->set("Cache-Control", "no-cache,no-store, must-revalidate");
return $response;
}
}
核
protected $routeMiddleware = [
....
// CUSTOM MIDDLEWARE GOES HERE
'clear.cache' => \App\Http\Middleware\ClearCache::class,
];
ROUTES
<?php
Route::group(['middleware' => 'guest'], function() {
Route::get('/', function() {
return view('welcome');
});
});
Auth::routes();
Route::group(['middleware' => 'auth'], function() {
Route::group(['middleware' => 'clear.cache'], function() {
Route::get('/home', '[email protected]');
});
});
LO後在用戶點擊後退按鈕時重新導向登錄頁面。登出很好。任何幫助? :(
想象一下當你在Facebook上登錄後,你點擊返回按鈕,然後它將你重新導向到Facebook的登錄頁面嗎?是不是很煩人? –
當你使用Laravel時,它會自動重定向到/ home($ redirectsTo)客戶中間件強制用戶不能登錄。 – Adraqi
我明白了,謝謝@Adraqi。 –