InertiaJS Laravel delete preserveScroll not working

Viewed 37

I am building a simple crud just to try Inertiajs and on my delete action I expect the page not to move as during any ajax call. It however kind of reloads the page and the scroll position changes.

Is this expected behaviour ?

Please see my code: Controller:

public function destroy($id)
{
    Client::find($id)->delete();

    return redirect()->back()
    ->with('message', 'Article Created Successfully.');
}

vuejs component:

setup(props, context) {
    const destroy = (id) =>  {
        Inertia.delete(route('clients.destroy', {id}), {
            preserveScroll: true,
        });
    }

    function edit(client) {
        context.emit('update-client', {client});
    }
    
    return {
        destroy,
        edit,
    }
}

As you can see I am using preserveScroll: true, and I return redirect. It works for my store action. I wonder if its not supported for delete ?

Thanks.

Edit1: Solution for this issue was that i had to change the anchor element to button:

from:

<a href="#" class="text-indigo-600 hover:text-indigo-900" @click="destroy(client.id)">Delete</a>

to:

<button class="text-indigo-600 hover:text-indigo-900" @click="destroy(client.id)">Delete</button>
0 Answers
Related