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

KeithHalsey's avatar

Inertia vs. Vue Pinia and Router

I've written one SPA using Laravel and Vue 3 and using a pinia store and routing done in Vue router. I'm now looking at starting a new project and have thought about using Inertia. My understanding is that this would then mean I would need to use either pinia or vue router. But I'm not sure this is necessarily a good thing as

a) it seems to couple my laravel backend and my vue frontend too closely (theoretically I could just right a new front end in svelte and I wouldn't have to change the laravel bit at all). conceptually its nice to keep them separate.

b) it seems that using pinia / vue router whilst maybe a little more complex, and I'm aware that inertia can do lazy loading & partial reloading of data, but the former give more control on a large project as to what data is loaded and when. Inertia may be good to get up and running quickly but may not scale in the same way.

Please let me know your thoughts / experiences. (I guess I could go the full hog and learn Nuxt, but I don't want to go there - I like Laravel too much)

0 likes
4 replies
LaryAI's avatar
Level 58

Inertia.js and Vue with Pinia and Vue Router serve different purposes and have different philosophies when it comes to building a web application. Here's a breakdown of the considerations you mentioned:

a) Coupling between backend and frontend: Inertia.js does indeed couple your frontend and backend more closely than a traditional SPA setup with Vue, Pinia, and Vue Router. Inertia allows you to create server-driven single-page apps without building an API. It works by returning server-side responses that Inertia can handle on the client side, which means your backend is responsible for routing and can directly pass data to your Vue components.

If you want to maintain a strict separation between your frontend and backend, or if you plan to have multiple frontends (e.g., web and mobile) that consume the same API, then sticking with Vue, Pinia, and Vue Router might be a better choice. This way, your Laravel backend would only serve as an API, and you could swap out the frontend technology without affecting the backend.

b) Control over data loading: With Vue, Pinia, and Vue Router, you have granular control over data fetching and state management. You can decide exactly when to fetch data, how to cache it, and how to update it. This can be beneficial for large projects where performance and data management are critical.

Inertia.js simplifies the process by handling data passing as part of the page visit. It can indeed do lazy loading and partial reloads, but you might find that for very complex state management scenarios, you might prefer the explicit control that Pinia provides.

Inertia.js is great for projects where you want to get up and running quickly and prefer to write your routing and controllers in Laravel. It's also beneficial if you want to avoid the complexity of managing an API and prefer a more monolithic approach.

Ultimately, the choice between Inertia.js and Vue with Pinia and Vue Router depends on your project requirements and personal preferences. If you value a strict separation of concerns and need fine-grained control over state and routing, you might stick with Vue, Pinia, and Vue Router. If you prefer a more integrated approach and are comfortable with the coupling that Inertia.js introduces, then Inertia could be a good fit.

Here's a simple example of how you might use Inertia.js in a Laravel controller:

use Inertia\Inertia;

public function index()
{
    $users = User::all();
    return Inertia::render('Users/Index', ['users' => $users]);
}

And in your Vue component, you would access the users prop directly:

<template>
  <div>
    <ul>
      <li v-for="user in users" :key="user.id">{{ user.name }}</li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    users: Array
  }
}
</script>

In contrast, with Vue and Pinia, you would fetch the data from an API endpoint using an Axios call within a Pinia action, and then use Vue Router for client-side routing.

Remember that there's no one-size-fits-all solution, and the best choice depends on the specific needs of your project.

gych's avatar

@KeithHalsey I'm glad it was helpful :) If this answered your question don't forget to close your thread by selecting the best answer.

Please or to participate in this conversation.