Inertia Link in Laravel 13 + Vue 3: from InertiaLink to Wayfinder

- Andrés Cruz - ES En español

Video thumbnail

of an Inertia application —ideal for our Drag and Drop forms— you must use Inertia's <Link> component. It is a lightweight wrapper around the standard <a> anchor tag that intercepts click events and prevents full page reloads. That is precisely how Inertia provides a single-page application (SPA) experience.

Technically, when the user clicks a <Link>, Inertia makes background XHR/fetch requests to the server to swap only the necessary page component, without reloading all assets. This makes navigation much faster than in a traditional web application.

Main features and attributes

You can customize the behavior of your Inertia links by passing the following properties:

  • href: specifies the target URL or route. For example: <Link href="/dashboard">Dashboard</Link>.

  • method: changes the HTTP verb from the default GET to POST, PUT, PATCH, or DELETE. Useful for mutating operations that, for accessibility, should be rendered as buttons (see below).

  • as: changes the rendered HTML element from an <a> tag to another one, such as a <button>. It is the recommended solution to avoid accessibility warnings.

  • preserve-scroll: prevents the page from jumping to the top when clicked, keeping the user's current scroll position.

  • preserve-state: keeps the local state of a page component intact (such as unsubmitted form inputs) without completely re-rendering it.

  • data: allows sending specific objects or payloads along with the request, similar to what you would do with a form.

Basic example

In a Vue 3 application, simply replace your standard <a> tags with Inertia's <Link> component:

// Vue 3 Example
<script setup>
import { Link } from '@inertiajs/vue3'
</script>

<template>
  <Link href="/profile" method="post" as="button" preserve-scroll>
    Update Profile
  </Link>
</template>

HTTP Methods

You can specify the HTTP method for any request from the <Link> component. The default value is GET, but you can also use POST, PUT, PATCH, and DELETE. For example, to log out with a POST request:

import { Link } from '@inertiajs/vue3'
<Link href="/logout" method="post">Logout</Link>

Custom headers

You can also include custom HTTP headers in your requests using the :headers prop:

import { Link } from '@inertiajs/vue3'
<Link href="/endpoint" :headers="{ foo: bar }">Save</Link>

Replacing the history stack when navigating

By default, each visit to a page pushes a new state into the browser history via window.history.pushState. However, it is possible to replace the current state using window.history.replaceState, setting the replace attribute to true. This prevents accumulating a new entry in the history, which can be useful in redirect flows or intermediate navigation steps:

import { Link } from '@inertiajs/vue3'
<Link href="/" replace>Home</Link>

The modern approach: Laravel + Wayfinder for routes

Now let's look at the most current setup using Wayfinder. Although at first it may seem a bit complex, its goal is to completely automate communication between Laravel and Vue, eliminating the need to write URLs manually.

Previously, we relied on external packages like ziggy-js to have a route() function that autocompleted routes in the frontend. Now, with the new Inertia 3 ecosystem, the approach is to generate TypeScript files that "map" our PHP routes directly to typed JavaScript functions, with autocomplete included in the IDE.

The route generator (the "weird" files)

If you check your project, you will see automatically generated files with content that may look unreadable at first glance. These files are the result of a command that scans your Laravel controllers and creates ready-to-use functions in Vue, with their HTTP methods and URLs already defined.

resources/js/routes/category/index.ts

export const index = (options?: RouteQueryOptions): RouteDefinition<'get'> => ({
    url: index.url(options),
    method: 'get',
})
***
export const store = (options?: RouteQueryOptions): RouteDefinition<'post'> => ({
    url: store.url(options),
    method: 'post',
})

If they don't generate on their own, you can run the command manually (although on Windows it can sometimes give cache errors):

$ php artisan wayfinder:generate

This command generates an action map (Actions). For example, for our CategoryController, it will create a store() function that already knows it must use the POST method and which specific URL to target, eliminating any chance of error when writing them by hand.

Normally, Wayfinder creates these files automatically when registering controller routes, so you won't have to run the command on every change.

When using Wayfinder together with the <Link> component, you can pass the resulting object directly to the href prop. The component will infer the HTTP method and URL directly from the Wayfinder object, which makes the code cleaner and safer:

import { Link } from '@inertiajs/vue3'
import { show } from 'App/Http/Controllers/UserController'

<Link :href="show(10)">Andrew</Link>

router object and preserveScroll

Video thumbnail

When working with forms or CRUD operations in Laravel + Inertia, it is common to run into UI synchronization issues, especially when we want to refresh data after an operation without resorting to a window.location.reload(). Although that approach "works", it is bad practice: it causes inconsistencies, UI flickers, and breaks the SPA model that Inertia provides.

NOT recommended example (though useful as a last resort):

create() {
   this.todoSelected = 0
   router.post(route('todo.store'), { name: this.form.name })

   setTimeout(() => window.location.reload(), 500) // ❌ Horrible pero funcional
}

The problem is that the setTimeout is not synchronized with the actual server operation, so it may trigger the reload too early (before the server has responded) or too late (adding an unnecessary wait).

✅ Real solution: use the router callbacks

Inertia provides callbacks that execute based on the request state. With them you can react at the exact right moment, without timers or manual reloads:

  • Callback    When it runs
  • onBefore    Before starting the visit
  • onStart    When Inertia starts processing
  • onProgress    During file uploads
  • onSuccess    When the request was successful
  • onError    When there are validation or server errors
  • onFinish    Whenever it finishes (with success or error)

General syntax:

router.<method>(url, data, {
   onBefore: visit => {},
   onStart: visit => {},
   onProgress: progress => {},
   onSuccess: page => {},
   onError: errors => {},
   onFinish: visit => {},
})

✅ Real example: delete a TODO and update the list without reloading

The onSuccess callback is the most widely used in CRUD operations. The logic looks like this:

router.delete(route('todo.destroy', this.deleteTodoRow), {
   onSuccess: (page) => {
       console.log(page.props.todos)
       this.dtodos = page.props.todos
   },
})

What is page?

It is the response object that Inertia returns after a successful visit. It contains:

  • component — the name of the current page's Vue component
  • props — the data that the Laravel controller sent to the view
  • url — the current URL
  • version — Inertia's asset version

Inside page.props come the same data you send from the server. In our case, page.props.todos contains the updated list of TODOs after deletion, which we reassign directly to the component state (this.dtodos) without needing to reload the page.

✅ Preserving scroll

Another typical issue: the scroll "jumps" to the top every time Inertia updates the virtual page. The solution is as simple as adding preserveScroll: true to the request options:

router.delete(route('todo.destroy', this.deleteTodoRow), {
   preserveScroll: true,
   onSuccess: (page) => {
       this.dtodos = page.props.todos
   },
})

With preserveScroll: true, the interface keeps its exact position on screen, considerably improving the user experience in long lists or tables.

Important notes on implementation

The hardest part is usually structuring the three arguments of the router properly: the route, the data, and the options object with the callbacks. Here is a properly structured example for an update:

router.put(
   route('todo.update', this.todo.id),
   { name: this.form.name },     // ← data
   {
       preserveScroll: true,     // ← opciones
       onSuccess: (page) => {
           this.dtodos = page.props.todos
       }
   }
)

⭐ Conclusion and final recommendation

To avoid reloading the page and solve synchronization issues, always use the router callbacks, especially:

  • onSuccess → when you want to apply changes based on the server response
  • onFinish → if you want to run something always, regardless of the outcome
  • preserveScroll → to keep the user's scroll position

Clean final example:

router.delete(route('todo.destroy', this.deleteTodoRow), {
   preserveScroll: true,
   onSuccess: (page) => {
       this.dtodos = page.props.todos
   },
})

With this approach:

  • there is no need for setTimeout
  • there is no manual page reload
  • scroll position is not lost
  • data stays properly synchronized with the server response

Deleting records in CRUD with the Link component

Video thumbnail

Another very common use of Inertia's <Link> component is triggering record deletion directly from the view, without needing a full form.

Let's implement the functionality to delete a category. We place a new link using the <Link> component and specify the DELETE method in the actions <td> of the listing.

Since <a> links always make GET requests, we must explicitly indicate that we want to send a DELETE request using the method="delete" prop:

resources/js/Pages/Dashboard/Category/Index.vue

***
<td class="p-2">
   <Link :href="route('category.edit', c.id)">Edit</Link>
   <Link method="DELETE" :href="route('category.destroy', c.id)">Delete</Link>
</td>
***
  • method="delete" → Inertia will send a DELETE request to the server.
  • as="button" → avoids the console warning and turns the <Link> into a button.
  • type="button" → optional, but recommended for greater semantic clarity.

From the controller, the code is the exact same as in any basic Laravel application: calling Eloquent's delete() function on the model bound via Route Model Binding:

app/Http/Controllers/Dashboard/CategoryController.php

public function destroy(Category $category)
{
   $category->delete();
}

Also remember to register the destroy route in your routes file, indicating that it will receive the category model as a parameter:

Route::delete('/category/{category}', [CategoryController::class, 'destroy'])
->name('category.destroy');

If you check the browser console from the categories Index.vue component, you will see a warning similar to this:

...links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues. Instead, consider using a more appropriate element, such as a <button>.

As the warning indicates, rendering an <a> link for destructive operations is not recommended practice, since the user could accidentally open the operation in a new tab. To avoid this, simply turn the <Link> into a button with the as="button" prop:

<Link as="button" type="button" method="DELETE" class="text-sm text-red-400 hover:text-red-700 ml-2" :href="route('category.destroy', c.id)">Delete</Link>

From InertiaLink to Link: the name migration

Let's talk about an important change introduced by recent Inertia updates for Laravel: renaming the main Vue component. It is an internal organization change that, although it's only a name change, requires updating all your imports.

You can see the official detail of the change here: https://inertiajs.com/releases/inertia-vue3-0.5.0-2021-07-13

The old <InertiaLink> is now simply called <Link>:

<inertia-link method="DELETE" :href="route('user.destroy', { customer: u })">Borrar</inertia-link>

To use it, you must import it from the package corresponding to your Vue version:

import { Link } from '@inertiajs/vue3' // Vue 3

or

import { Link } from '@inertiajs/vue' // Vue 2
components: {
   ...
   Link
},

Once imported, usage is the exact same; in that respect there is no functional change:

<Link method="DELETE" :href="route('user.destroy', { customer: u })">Borrar</Link>

Resolving the warning: "links is discouraged as it causes Open Link in New Tab/Window"

Video thumbnail

If you checked the browser console after deleting a record, you surely saw this warning:

"Using <Link> for POST, PUT, PATCH or DELETE requests is discouraged."

This happens because Inertia's <Link> component is designed for navigation, not for mutating operations (create, update, delete). When used with methods like DELETE, the rendered element is still an <a>, which creates accessibility issues: a user could open that "link" in a new tab and execute the deletion without confirmation.

✔ Solution recommended by Inertia

Convert the <Link> into a <button> element using the as prop:

<Link
   method="delete"
   :href="route('todo.destroy', todo.id)"
   as="button"
>
   Eliminar
</Link>

You can also add type="button" for greater semantic clarity, although it is not strictly necessary:

<Link
   method="delete"
   :href="route('todo.destroy', todo.id)"
   as="button"
   type="button"
>
   Eliminar
</Link>

With this change:

  • The warning no longer appears in the browser console.
  • You still take advantage of Inertia's <Link> functionality.
  • The element behaves like a native button, which is the semantically correct way for non-navigational operations.

Conclusions

In short, the Inertia ecosystem has evolved considerably. The change from <InertiaLink> to <Link> is just the first of several adjustments that simplify and modernize how we manage SPA navigation. Integration with Wayfinder takes this a step further, automatically generating typed TypeScript routes from your Laravel controllers, which eliminates typos and improves IDE autocomplete.

The next step is learning how to use confirmation dialogs in Laravel Inertia, essential before executing any destructive operation such as deleting records.

Learn how to use the Inertia.js 3 `Link` component in Laravel 13 with Vue 3: HTTP methods, `preserveScroll`, router callbacks, and the new approach using Wayfinder.


Únete a la comunidad de desarrolladores que han decidido dejar de picar código y empezar a construir productos reales. Recibe mis mejores trucos de arquitectura cada semana:

I agree to receive announcements of interest about this Blog.