Using Laravel 11 with InertiaJS and Svelte.
I have an admin.php file which has some routes guarded by the auth middleware. I want the "/admin" route to redirect to /admin/posts
, or /login
if the user is not logged in. Using Inertia's <Link>
component, navigating to this route should redirect to /admin/posts
or /login
and not refresh the app.
Instead it returns All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.
Searching a bit, I found Inertia needs the X-Inertia
header, but it's present in the response headers.
The website is behind Nginx Proxy Manager. It's set to pass headers X-Inertia
and X-Inertia-Version
.
Website is live for now on https://pwa.skmedia.cc. Navigating to "Administracija" should return the error. Code is on github here
The website works locally when served with php artisan serve
, but when deployed on a server behind Nginx Proxy Manager, redirected Inertia Links return the error. Redirecting back with redirect()->back()
works fine, but I want to redirect to some other page.
I can use Inertia::location()
, but this refreshes the page which I would like to avoid.
e.g. in web.php
if i have:
Route::get('/redirected', function(){ return redirect()->to('/destination'); });Route::get('/destination', function(){ return Inertia::render('Example'); });
In resources/js/Pages
an empty Example.svelte
file, and in my navigation something like:
<script> import { Link } from "@inertiajs/svelte";</script><Link href="/redirected">Redirected</Link>
Clicking on that link on the website in "production" returns:
All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.
while locally it redirects correctly to /destination
.