Post from Vue with router.post

router.post sends one action that has no fields. useForm is the right call when the user is typing.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/inertia-router-post-vue.md
router.post sends one action that has no fields. useForm is the right call when the user is typing.
Do not send a logout through router.get.
Do not add Vue Router's push after router.post.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Inertia router.post” use it for every button, including forms that need errors. router.post is for a click that has no fields: publish, archive, log out.

TL;DR

  • router.post sends one action that has no fields.
  • useForm is the right call when the user is typing.
  • Do not send a logout through router.get.
  • Do not add Vue Router’s push after router.post.

Who it's for: Laravel + Vue developers on Inertia

Applies to: Laravel 13 · Inertia 3 · Vue 3

The fix#

vue
<script setup lang="ts">
import { router } from "@inertiajs/vue3";

function publish(id: number) {
  router.post(`/posts/${id}/publish`, {}, { preserveScroll: true });
}
</script>

The second argument is the body. An empty object is a POST with no fields. The Laravel route still has to be post, and the controller still checks the policy.

When the user typed a title, use useForm so form.errors.title exists. router.post does not give you that object. You would be reading errors off the page props by hand.

What to avoid#

Gotcha

Do not send a logout through router.get. Logout is a POST so a random page cannot log the user out with an image. Do not add Vue Router’s push after router.post. Inertia follows the redirect the controller returns.

FAQ#

How do I post from Vue with router.post?

router.post sends one action that has no fields. useForm is the right call when the user is typing.

What goes wrong with Inertia router.post?

Many developers use it for every button, including forms that need errors. Do not send a logout through router.get.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.