Hi I am using inertia in my laravel application but I send post request from vue to backend request is fulfilled I mean record is created deleted or updated in database but redirects are not working .
Backend Code
public function create(Request $reqeust)
{
$validated = $reqeust->validate([
'name' => 'required',
'email' => 'required',
'password' => 'required'
]);
if ($validated) {
Dealer::create($validated);
return redirect()->route('dealers');
}
return redirect()->back();
}
Error
Uncaught (in promise) TypeError: this.resolveComponent is not a function
at n2.setPage (router.ts:378:33)
at router.ts:323:19
The error message suggests that there is an issue with resolving the component for the page. One possible solution is to use the Inertia::location() method to redirect instead of the Laravel redirect() method. Here's an example:
public function create(Request $request)
{
$validated = $request->validate([
'name' => 'required',
'email' => 'required',
'password' => 'required'
]);
if ($validated) {
Dealer::create($validated);
return Inertia::location(route('dealers'));
}
return redirect()->back();
}
This should redirect the user to the dealers page after creating a new dealer record. Make sure to import the Inertia facade at the top of your controller:
use Inertia\Inertia;
If this solution doesn't work, it's possible that there is an issue with your Vue components or router configuration.
I've got the same error when following Inertia Forms 101, return redirect('/users'); gives the error, along with return redirect()->back(); inertia docs say to use return to_route('users'); which also gives the error. Currently I'm using return Inertia::location(route('users')); which I don't feel is correct. If anyone can shed some light on this it would be great. Thanks