#Nuxt 4: serve index.vue from outside of app layer
1 messages · Page 1 of 1 (latest)
Yes, it is possible to serve the index.vue page from outside the app/ directory in Nuxt 4 using layers. You can indeed create a 'home' layer and put index.vue in layers/home/pages/.
Nuxt layers allow you to extend the default files, configs, and much more. They provide a powerful way to share and reuse partial Nuxt applications within a monorepo, from a git repository, or from an npm package.
Here's how you can achieve this:
-
Create a 'home' layer in your project:
layers/ home/ pages/ index.vue -
In your
nuxt.config.ts, extend your configuration to include the 'home' layer:
export default defineNuxtConfig({
extends: [
'./layers/home'
]
})
This setup will allow Nuxt to use the index.vue file from your 'home' layer as the main page of your application.
It's important to note that layers follow a similar structure to a standard Nuxt application, making them easy to author and maintain. The pages/ directory in your layer will be auto-scanned and used by Nuxt for the project extending this layer.
For more detailed information on how to work with Nuxt layers, you can refer to the Nuxt documentation on Layers (https://nuxt.com/docs/guide/going-further/layers).
Nuxt documentation on Authoring Nuxt Layers (https://nuxt.com/docs/guide/going-further/layers) provides more in-depth information about creating and using layers in Nuxt applications.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@heavy coral Kapa.ai is still learning and improving, please let me know how I did by reacting below.