I have a modal in vue where I call this function
const createChat = async (id) =>{
try {
const response = await axios.post('/pdf-chat/create-chat', {
name: name.value,
pdfId: id,
});
dialogVisible.value = false;
console.log(response)
} catch (error) {
console.error('Error sending message:', error);
}
}
The controller function called,the route exists
public function createChat( Request $request)
{
$chat = new Chat();
$chat->name = $request->name;
$chat->save();
$pdf = Upload::find($request->pdfId);
return Inertia::location(route('pdf-chat', ['chat' => $chat->hash, 'pdf' => $pdf->hash]));
}
And the next request is the redirect url with 200 code but I stay on the same page,nothing in the browser`s url changes.
If a copy the url and paste it in the browser it works fine.
Any thoughts? Laravel 10,Vue 3 ,Inertia 1.*
2
Answers
Don’t use (it’s only for External redirects):
Inertia::location()
use:
to_route('pdf-chat', ['chat' => $chat->hash, 'pdf' => $pdf->hash])
Instead of using Axios to make the request, use Inertia’s
router.visit
or one of their helpers likerouter.get
. These will intercept the request and know how to handle the response.See https://inertiajs.com/manual-visits