Sails.js & Vue.js - Part 3

von Manuel am 16.11.2025 um 12:00 Uhr

Excellent. The enchanted shipyard has provided us with a state-of-the-art vessel. Now it’s time to step inside and bring its instruments to life. We will begin with the most crucial room on any ship: the Chart Room.


Part 3: The Living Chart Room (Building with Inertia & Vue)


Chief Architect’s Briefing (Background and Theory)

Our inertia-flagship is ready. The core task now is to build out a feature. We will create a “Chart Room” where the captain can view a list of known destinations and plot new ones.

This process will demonstrate the complete, magical end-to-end flow of the Modern Monolith:

  1. A user will click a <Link> component on our homepage to navigate to /chartroom.
  2. Our Sails router (config/routes.js) will direct this request to a new ChartRoomController.
  3. The controller will use a Destination model to fetch all known destinations from the database.
  4. The controller will then pass this list of destinations as props to a Vue page component using res.inertia('ChartRoom', { destinations: allDestinations }).
  5. Our ChartRoom.vue component will receive the destinations array as a prop and use a v-for loop to display it.
  6. Inside the ChartRoom.vue component, we will build a form. When submitted, this form will use an Inertia helper (useForm) to POST data to a new Sails endpoint. This helper gracefully handles loading states and validation errors for us.
  7. The Sails controller action will process the form data, create a new Destination in the database, and then issue a res.redirect('/chartroom').
  8. Inertia intercepts this redirect, automatically re-fetches the props for /chartroom (which now include the new destination), and updates the page.

Notice: no manual fetch calls, no manual JSON parsing, no manual page refreshing. It’s a seamless conversation between the backend and frontend.


Key Concepts Checklist


Mission Log: Quest - “Plotting the Course”


Mission Debrief (Review & Outcomes)

Outstanding, Admiral. The Chart Room is now a living instrument. You have mastered the fundamental workflow of a modern Sails + Inertia application. You’ve passed data as props, navigated with <Link>, and handled form submissions with useForm, all while keeping your controller logic clean and familiar.

You can see how this pattern removes immense complexity. The front-end doesn’t need to know how to re-fetch the list; it just submits a form. The back-end doesn’t need to return special JSON; it just creates data and issues a standard redirect. Inertia handles the complex conversation between them, letting each side focus on what it does best.


Rewards