inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.01k stars 224 forks source link

Laravel redirect response not working #550

Closed friendlyhomosapien closed 10 months ago

friendlyhomosapien commented 10 months ago

I'm building a Vue app in my Laravel project using Inertiajs. When using the form helper and/or the router function I try to do a request to an endpoint that returns a redirect. Inertia responds to this with "All Inertia requests must receive a valid Inertia response, however a plain JSON response was received."

In my Vue page:

const form = useForm({
    email: null,
    password: null,
    remember: false
});

function submit() {
    form.post('/test');
}

in my endpoint controller method: return redirect()->route('scanV2.index');

reinink commented 10 months ago

Hey! So this happens when you redirect to a page that isn't an Inertia response. All responses to an Inertia request must be a valid Inertia response — JSON responses are not supported. If you want to return JSON from a response then I'd recommend just using XHR/fetch instead. However generally you can find ways to make this work but just returning a valid Inertia response and providing some updated data as props.

Hope that helps!