Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ibrahim-elshorbagy's avatar

Laravel React Inertia | when client open it from browser history it open JSON return not a component

i have problem with all Inertia Projects when the user open the page from his browser history it open a JSON not a react page how can i prevent this i have

"dependencies": { "@inertiajs/react": "^2.0.12", "axios": "^1.10.0", "react": "^19.1.0", "react-dom": "^19.1.0", "swiper": "^11.2.8", "vite": "^6.3.5", "ziggy-js": "^2.5.3" },

0 likes
4 replies
ibrahim-elshorbagy's avatar

which part exacly it is a big project i added this code public function handle(Request $request, \Closure $next) { $response = parent::handle($request, $next);

if ($request->header('X-Inertia')) {
  $response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate, private');
  $response->headers->set('Pragma', 'no-cache');
  $response->headers->set('Expires', '0');
}

return $response;

}

and still happend on it

JussiMannisto's avatar

How did you configure Inertia? How are you navigating between pages? There's something wrong with the setup or how you're using Inertia if you see JSON responses through the browser history. Without seeing any code, it's hard to say what's wrong. I've never seen that myself.

That middleware is unnecessary and does nothing when you're navigating from history, since the X-Inertia header is only present in XHR requests sent by Inertia.

Please or to participate in this conversation.