Hey, I've been building quite a bit with Nuxt and the site has gotten big, so i have quite a lot of index.vue files. I was wondering if i can somehow set up a file name only prefix, like users:index.vue / users:[id].vue / roles:index.vue etc. Fuzzy search with directory in IDE hasn't really been helpful. Is there something built in or do you have a build time hook suggestion?
#Custom page file name prefix that should not affect generated route
3 messages · Page 1 of 1 (latest)
Hi @dense zenith. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
I'm sorry, but the knowledge sources do not mention any built-in Nuxt feature that allows you to use custom file name prefixes (like users:index.vue or roles:index.vue) for page components without affecting the generated route structure. Nuxt's routing is convention-based and relies on the directory and file names within the pages/ directory to generate routes. The standard approach is to use index.vue for default routes within a directory, and dynamic routes with [param].vue syntax.
There is, however, a feature that allows you to specify glob patterns for which files are scanned as pages, which could help you exclude certain files (like tests), but it does not provide a way to use custom prefixes for page files while keeping the route unchanged:
export default defineNuxtConfig({
pages: {
pattern: ['**/*.vue', '!**/*.spec.*'],
},
})
feat(nuxt): allow specifying glob patterns for pages