Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brunokaue's avatar

Inertia Link Confirm

I was watching the Build Modern Laravel Apps Using Inertia.js, it's very good. I learn much watching.

But now i need to implement a confirm before send a link ... someone can help me?

0 likes
11 replies
Sinnbeck's avatar

Please describe what the problem is. What have you tried? How do you expect it to work?

furqanDev's avatar

Inertia Link is just an <a></a> tag but with much more flexibility. If you are using Vue then you can just prompt a message when user click on the Link

https://inertiajs.com/links

thewebartisan7's avatar

In case someone else is looking for the same question, Inertia Link has an undocumented way to prevent visit, using onBefore event, if you return false, it will not do the visit:

<Link :href="route('users.destroy', user)" method="delete" as="button" type="button" :onBefore="() => window.confirm('Are you sure?')">Delete</Link>
7 likes
Dev_Marcos's avatar

Hi ! I was looking for this same answer. The solution of @thewebartisan7 dosn't work for me. So i do some changes: I replaced this:

 < Link :href="route('user.delete',id)" class="border rounded-md px-3">Delete< /Link > 

For:

< button @click="remove" class="border rounded-md px-3" >Delete< /button >

So the method remove:

 function remove(){
		Inertia.visit(route("user.delete",props.id),{ 
            onBefore: () => confirm('Are you sure?'), 
    });
}

Regards.

davidblanco1012's avatar

this worked for me:

<Link :href="route('users.destroy', user)" method="delete" as="button" type="button" :onBefore="() => confirm()">Delete</Link>

and the confirm method in JS:

function confirm(){
        return window.confirm("Are you sure?");
}
3 likes
hiroshikadokura's avatar

This worked for me:

            <Link
                        as="button"
                        type="button"
                        method="delete"
                        onClick={(e) => {
                            if (!window.confirm("are you sure?")) {
                                e.preventDefault();
                            }
                        }}
                        href={route("spots.destroy", spot.id)}
                    >
                        Delete
                    </Link>
1 like
bkkrishna's avatar

Anyone had any luck with changing the confirmation UI like implementing some SweetAlert confirmations? It's annoying that it can only show a basic alert like dialogue box and customization is like impossible as async operations aren't yet supported by onBefore() hook. Kindly, shade some light if someone has any workarounds on this. Can't get the following to work:

Please or to participate in this conversation.