vite-plugin-vue-layouts-next is a Vite plugin designed to streamline layout management for Vue 3 applications, particularly when integrated with Vue Router. It's a maintained and improved fork of the original `vite-plugin-vue-layouts`, providing robust support for the latest ecosystem versions including Vite 8, Vue 3, and Vue Router 5. The plugin automatically processes Vue components in a designated `layouts` directory, allowing pages to declare their desired layout via route meta fields (e.g., using `lang="yaml"` blocks). It currently stands at version 2.1.0, with a recent release cadence demonstrating active development to keep pace with its peer dependencies. A key differentiator is its explicit compatibility with newer major versions of Vite and Vue Router, making it a suitable choice for projects on these updated stacks. It is also designed to work seamlessly with `vite-plugin-pages` for comprehensive auto-routing and layout solutions.
npm install vite-plugin-vue-layouts-nextVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `vite-plugin-vue-layouts-next` into a Vite project using `vite.config.ts` and how to set up the generated layouts with Vue Router, specifically showing integration with `vite-plugin-pages` generated routes and the necessary TypeScript client types.
Review the official Vue Router 5 migration guide if upgrading your router. If staying on Vue Router 4, consider pinning `vite-plugin-vue-layouts-next` to `<2.0.0` or ensure your setup (`main.ts`) correctly handles the `setupLayouts` function's expected input for your Vue Router version.
Update your Vite installation to a compatible version (6, 7, or 8) or ensure your `package.json`'s `vite` entry aligns with the plugin's peer dependency requirements.
Consider installing and configuring `vite-plugin-pages` for a more integrated and automated routing experience. If not using `vite-plugin-pages`, ensure your manual route definitions are compatible with the `setupLayouts` function.
Ensure you have a `default.vue` component in your `src/layouts` directory (or specified `layoutsDirs`). Alternatively, configure the `defaultLayout` option in the plugin's settings to point to your desired fallback layout file name.
Add `"vite-plugin-vue-layouts-next/client"` to the `types` array in your `tsconfig.json` under `compilerOptions`.
Add `"vite-plugin-vue-layouts-next/client"` to the `compilerOptions.types` array in your `tsconfig.json`.
Ensure `vite-plugin-pages` is correctly configured and running before `vite-plugin-vue-layouts-next`, and that `setupLayouts` is passed the output of your page generation. Also, verify that your default layout (`default.vue`) and any specified layouts exist in your `layoutsDirs`.
Ensure `Layouts()` is called as `plugins: [Vue(), Pages(), Layouts()]` where `Pages()` comes before `Layouts()` if you are using `vite-plugin-pages`. Verify all plugin calls are correctly array members within `defineConfig`.