eidellev / inertiajs-adonisjs

279 stars 17 forks source link

Redirects with inertia.location don't work because X-Inertia=true header is sent #71

Closed finestgecko closed 2 years ago

finestgecko commented 2 years ago

I had some problems using inertia.location(...) in my application.

According to the Inertia docs, the server should send a 409 Conflict response, with the destination in the X-Inertia-Location header.

Looking at the request, it does indeed do this. However, there are two Inertia headers:

x-inertia true
x-inertia-location http://<redacted>/auth/login

I asked for help in the Discord channel for Inertia and it was pointed out to me that:

So, instead of using inertia.location(), I set the headers manually:

response.header('X-Inertia-Location', <some url>)
response.removeHeader('X-Inertia') // 👈 removing X-Inertia
return response.conflict()

... and it works perfectly.


Also, on a side note, using inertia.location() causes a TypeScript error:

Property 'location' does not exist on type 'InertiaContract'.
eidellev commented 2 years ago

Hey @joelcieslar ! Thank you reporting this and for going the extra mile with the details. It's been fixed in v6.2.1.

Feel free to reopen if you run into additional issues.