Question:
Inertia redirect issue in Laravel with Vue

Problem:

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


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.*


Solution:

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


Suggested blogs:

>How to create a One Page App with Angular.js, Node.js and MongoDB?

>Complete guide to Perform crud operation in angular using modal popup

>How to get item details of Woo Commerce in custom email content?

>PHP cURL to upload video to azure blob storage

>How to merge cells with HTML, CSS, and PHP?

>Python Error Solved: load_associated_files do not load a txt file

>How to build interactive_graphviz in Python


Nisha Patel

Nisha Patel

Submit
0 Answers