inertia
inertia copied to clipboard
Inertia redirects to wrong route
Versions:
"@inertiajs/inertia": "^0.11.0",
"@inertiajs/inertia-vue3": "^0.6.0",
Describe the problem:
I'm sending a form.post request from a contact component to the backend but for whatever reason inertia upon success redirects to the post route (/contact/submit) instead of the correct /contact route.
Steps to reproduce:
The post request is sent from contact.vue:
<script setup>
const submit = () => {
form.post('/contact/submit', {
preserveScroll: true
})
}
</script>
button:
<button type="button" @click="submit">Submit</button>
and routed in web.php:
Route::inertia('/contact', 'contact');
Route::post('/contact/submit', [ContactController::class, 'submit']);
and validated in ContactController.php before redirecting with the inertia helper:
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ContactRequest;
class ContactController extends Controller
{
public function submit(ContactRequest $request)
{
$request->validated();
return inertia('contact', ['success' => 'Your inquiry has been sent.']);
}
}
This should redirect to contact.vue which is routed to /contact (as you can see in web.php) but it redirects to /contact/submit instead. I don't know if I'm doing something wrong or if this is a bug.
So this redirects to the wrong route /contact/submit:
return inertia('contact', compact('success'));
but this redirects correctly to /contact:
return redirect()->route('contact')->with('success', 'Your inquiry has been sent.');
In post request, a redirect to a route seems more appropriate than returning a inertia page
Hey! Thanks so much for your interest in Inertia.js and for sharing this issue/suggestion.
In an attempt to get on top of the issues and pull requests on this project I am going through all the older issues and PRs and closing them, as there's a decent chance that they have since been resolved or are simply not relevant any longer. My hope is that with a "clean slate" me and the other project maintainers will be able to better keep on top of issues and PRs moving forward.
Of course there's a chance that this issue is still relevant, and if that's the case feel free to simply submit a new issue. The only thing I ask is that you please include a super minimal reproduction of the issue as a Git repo. This makes it much easier for us to reproduce things on our end and ultimately fix it.
Really not trying to be dismissive here, I just need to find a way to get this project back into a state that I am able to maintain it. Hope that makes sense! ❤️