From c4ae151de563f0a91f68f034386b9dfaec6c25b1 Mon Sep 17 00:00:00 2001 From: Horu <73709188+HigherOrderLogic@users.noreply.github.com> Date: Tue, 13 Aug 2024 07:16:04 +1000 Subject: [PATCH] feat(nuxt): allow organising pages within route groups (#28276) --- docs/2.guide/2.directory-structure/1.pages.md | 16 ++++++++++ packages/nuxt/src/pages/utils.ts | 32 ++++++++++++++++--- .../pages-override-meta-disabled.test.ts.snap | 28 ++++++++++++++++ .../pages-override-meta-enabled.test.ts.snap | 19 +++++++++++ packages/nuxt/test/pages.test.ts | 31 ++++++++++++++++++ test/basic.test.ts | 8 +++++ .../basic/pages/(new-group)/group-page.vue | 5 +++ .../nested-group/(deep-group)/group-page.vue | 5 +++ .../nested-group/(index-group)/index.vue | 5 +++ .../more-nested/(more-deep)/group-page.vue | 5 +++ 10 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/basic/pages/(new-group)/group-page.vue create mode 100644 test/fixtures/basic/pages/nested-group/(deep-group)/group-page.vue create mode 100644 test/fixtures/basic/pages/nested-group/(index-group)/index.vue create mode 100644 test/fixtures/basic/pages/nested-group/more-nested/(more-deep)/group-page.vue diff --git a/docs/2.guide/2.directory-structure/1.pages.md b/docs/2.guide/2.directory-structure/1.pages.md index 283846201d..1367f6f871 100644 --- a/docs/2.guide/2.directory-structure/1.pages.md +++ b/docs/2.guide/2.directory-structure/1.pages.md @@ -226,6 +226,22 @@ definePageMeta({ :link-example{to="/docs/examples/routing/pages"} +## Route Groups + +In some cases, you may want to group a set of routes together in a way which doesn't affect file-based routing. For this purpose, you can put files in a folder which is wrapped in parentheses - `(` and `)`. + +For example: + +```bash [Directory structure] +-| pages/ +---| index.vue +---| (marketing)/ +-----| about.vue +-----| contact.vue +``` + +This will produce `/`, `/about` and `/contact` pages in your app. The `marketing` group is ignored for purposes of your URL structure. + ## Page Metadata You might want to define metadata for each route in your app. You can do this using the `definePageMeta` macro, which will work both in `