Custom page file name prefix that should not affect generated route
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?2 Replies
Hi @ando. 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:
feat(nuxt): allow specifying glob patterns for
pages
If you want to improve file searchability in your IDE, you might consider restructuring your directories or using IDE-specific features, but as of now, Nuxt does not support custom file name prefixes for pages without affecting routing. If you need more advanced routing or file naming, you would likely need to implement a custom solution using Nuxt hooks or a build-time script, but there is no documented example of this in the provided knowledge sources.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@224469656176427008> Kapa.ai is still learning and improving, please let me know how I did by reacting below.