skip to Main Content

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]));
}

I get a redirect 302
enter image description here

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.
enter image description here

Any thoughts? Laravel 10,Vue 3 ,Inertia 1.*

2

Answers


  1. Don’t use (it’s only for External redirects):

    Inertia::location()

    use:

    to_route('pdf-chat', ['chat' => $chat->hash, 'pdf' => $pdf->hash])

    Login or Signup to reply.
  2. Instead of using Axios to make the request, use Inertia’s router.visit or one of their helpers like router.get. These will intercept the request and know how to handle the response.

    See https://inertiajs.com/manual-visits

    router.visit('/pdf-chat/create-chat', {
      method: 'get',
      data: {
        name: name.value,
        pdfId: id
      }
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search