vue-turbolinks is a JavaScript package designed to facilitate the integration of Vue.js components into applications that utilize Turbolinks or Hotwire's Turbo. Its primary function is to manage the lifecycle events of Vue components—specifically their proper setup and teardown—within the context of a Turbolinks/Turbo page navigation cycle. This allows developers to incrementally add interactive Vue elements to traditional server-rendered applications without converting them into full Single-Page Applications (SPAs). The current stable version is 2.2.2, with recent minor updates indicating active maintenance. A key differentiator is its explicit focus on solving the challenges of combining Vue's reactivity with Turbolinks'/Turbo's caching mechanisms, making it unsuitable and unnecessary for projects already employing client-side routing libraries like Vue Router.
npm install vue-turbolinksVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a Vue component using the `turbolinksAdapterMixin` on a `turbo:load` event, ensuring proper lifecycle management with Hotwire/Turbolinks. It includes a basic Vue component and simulates the DOM changes and events typical in a Turbo application.
If using a client-side router, remove `vue-turbolinks` as it provides no benefit and can introduce conflicts. If not using a client-side router, ensure Turbolinks/Turbo is correctly configured.
Always wrap Vue `<transition>` components within a standard DOM element (e.g., `<div>`) at the root level of your component's template. For example, instead of `<template><transition>...</transition></template>`, use `<template><div><transition>...</transition></div></template>`.
Upgrade to `vue-turbolinks` version 2.2.1 or higher to ensure the `turbolinksAdapterMixin` named export functions as expected.
Wrap your root `<transition>` component in a regular HTML element (e.g., `<div>`) in your Vue component's template.
Ensure `import Vue from 'vue';` is present at the top of your file or that Vue is globally exposed before attempting to install the adapter globally. If using Webpack, check your configuration for Vue aliasing.