0

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 2

3

Don't use (it's only for External redirects):

Inertia::location()

use:

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

Update:

I see now, because you are using axios you should use inertiajs router inertiajs.com/manual-visits

Sign up to request clarification or add additional context in comments.

3 Comments

Tried that at first,same thing.
I see now, because you are using axios you should use inertiajs router inertiajs.com/manual-visits
Edit your answer,it`s less fragile than comments.Thanks.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.