Sails.js & Vue.js - Part 2

von Manuel am 09.11.2025 um 12:00 Uhr

The traditional refit was a success, but it revealed the friction of the old ways. Now, we unleash the full power of the modern armada. We will cast the magical enchantment that fuses our Sails backend and Vue front-end into a single, seamless entity.


Part 2: The Magical Enchantment (Introducing Inertia.js)


Chief Architect’s Briefing (Background and Theory)

In our last mission, we had our Vue crew “shouting across the deck” to the Sails crew via API calls. It worked, but it was noisy and required building two separate communication systems.

Inertia.js is the magical, telepathic link between the two crews.

It’s not a framework; it’s a new approach to building classic server-driven web apps. It allows us to create fully client-side rendered, single-page apps without the complexity of building and consuming a separate API. As the team behind Inertia says, it’s “The Modern Monolith.”

Here’s how the magic works:

  1. A Link is Clicked: A user clicks a special <Link> component in your Vue front-end (e.g., <Link href="/logbook">).
  2. Inertia Intercepts: Instead of a full page reload, Inertia intercepts this click and makes a background request (an XHR/fetch request) to the Sails server.
  3. Sails Responds: Your Sails config/routes.js and controller work exactly as they did before. The controller fetches data from the database.
  4. The New Response: This is the key. Instead of calling res.view('logbook', { data }) or res.json({ data }), your controller calls a new response: res.inertia('LogbookPage', { data }).
  5. The Magic Payload: Sails sends back a special JSON response that contains two things: the name of the Vue component to render (LogbookPage) and the data as “props.”
  6. Vue Takes Over: Back in the browser, Inertia receives this payload, automatically finds the LogbookPage.vue component, and seamlessly swaps it into the view, passing the data directly to it as props.

The result? You write your back-end logic in Sails controllers as you always have, and your front-end logic in self-contained Vue components. Inertia handles the “glue” in between. The official inertia-sails adapter is designed precisely for this, letting you “have the power of Sails and the client-side framework of your choice in one codebase” blog.sailscasts.com.

Setting this up manually is complex. Thankfully, the Sails community has provided a powerful shipwright’s tool to do it for us.


Key Concepts Checklist


Mission Log: Quest - “The Enchanted Shipyard”

We will not refit our old ship. We will build a new one from the ground up using the most modern tools available, creating the perfect foundation.


Mission Debrief (Review & Outcomes)

Magnificent! You have just constructed a state-of-the-art vessel’s foundation in a fraction of the time it would have taken manually. You didn’t just build a ship; you built an enchanted shipyard, a development environment where the back-end and front-end are perfectly integrated from day one.

You now have a project where:

We haven’t built any custom features yet, but we have established the most powerful foundation possible. In our next mission, we will use this enchanted vessel to begin replacing static pages with fully interactive, data-driven Vue components.


Rewards