Redirect back after an Inertia form

back() returns to the page that posted. to_route() is the right call when the next page is a specific list.

For your AI agent

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

Read https://laravel-vuejs.space/inertia-redirect-back-vue.md
back() returns to the page that posted. to_route() is the right call when the next page is a specific list.
Do not return response()->json(['ok' => true]) from an Inertia action and then navigate in onSuccess.
Do not return back() from a test and assert a JSON body.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Inertia redirect back” return back() from a create form and land on the create form again. That is what back() means. The CRUD guide uses to_route('posts.index') after a save so the next page is the list.

TL;DR

  • back() returns to the page that posted.
  • to_route() is the right call when the next page is a specific list.
  • Do not return response()->json(['ok' => true]) from an Inertia action and then navigate in onSuccess.
  • Do not return back() from a test and assert a JSON body.

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

Applies to: Laravel 13 · Inertia 3 · Vue 3

The fix#

Use back() when the user should stay where they were. A row button on the list is the usual case:

php
public function publish(Request $request, Post $post): RedirectResponse
{
    $this->authorize('update', $post);
    $post->update(['published_at' => now()]);

    return back();
}

Inertia follows the redirect. The Vue page does not call router.visit after form.post unless you are doing something the redirect cannot express.

Use to_route() when the destination is fixed. Use redirect()->route('posts.edit', $post) after create when the next step is the editor.

What to avoid#

Gotcha

Do not return response()->json(['ok' => true]) from an Inertia action and then navigate in onSuccess. You dropped the redirect Inertia is built around. Do not return back() from a test and assert a JSON body.

FAQ#

How do I redirect back after an Inertia form?

back() returns to the page that posted. to_route() is the right call when the next page is a specific list.

What goes wrong with Inertia redirect back?

Many developers return back() from a create form and land on the create form again. Do not return response()->json(['ok' => true]) from an Inertia action and then navigate in onSuccess.

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.