From 630038dd0e21dad097677419e1866d1bf8b60138 Mon Sep 17 00:00:00 2001 From: Benicio Cardozo Date: Fri, 14 Oct 2022 11:25:28 -0300 Subject: [PATCH 1/4] fix(pages): add module when `router.options` is present --- packages/nuxt/src/pages/module.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index cdb075da5eb..6ef7001e1b2 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -17,9 +17,11 @@ export default defineNuxtModule({ const pagesDirs = nuxt.options._layers.map( layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages') ) - + + const isRouterOptionsPresent = nuxt.options._layers.some(layer => existsSync(resolve(layer.config.srcDir, 'app/router.options.ts'))) + // Disable module (and use universal router) if pages dir do not exists or user has disabled it - if (nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) { + if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) { addPlugin(resolve(distDir, 'app/plugins/router')) return } From 2a4077a4d774b8fc9b66073fc0fbbb7b7abd0700 Mon Sep 17 00:00:00 2001 From: Benicio Cardozo Date: Fri, 14 Oct 2022 11:40:43 -0300 Subject: [PATCH 2/4] docs: update to match new behavior --- docs/content/2.guide/2.directory-structure/1.pages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/2.guide/2.directory-structure/1.pages.md b/docs/content/2.guide/2.directory-structure/1.pages.md index f05e4db7cfd..6dfcc289098 100644 --- a/docs/content/2.guide/2.directory-structure/1.pages.md +++ b/docs/content/2.guide/2.directory-structure/1.pages.md @@ -10,7 +10,7 @@ head.title: "Pages" Nuxt provides a file-based routing to create routes within your web application using [Vue Router](https://router.vuejs.org) under the hood. ::alert{type="info"} -This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app), reducing your application's bundle size. +This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app) (unless you provide an [`router.options.ts`](/guide/directory-structure/pages#router-options), reducing your application's bundle size. :: ## Usage From 6ada93510294b91707ecb8895ead53dce11d31dd Mon Sep 17 00:00:00 2001 From: Benicio Cardozo Date: Fri, 14 Oct 2022 13:07:52 -0300 Subject: [PATCH 3/4] style: lint --- packages/nuxt/src/pages/module.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 6ef7001e1b2..88bcfd6ffbb 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -17,11 +17,11 @@ export default defineNuxtModule({ const pagesDirs = nuxt.options._layers.map( layer => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages') ) - - const isRouterOptionsPresent = nuxt.options._layers.some(layer => existsSync(resolve(layer.config.srcDir, 'app/router.options.ts'))) - + + const isRouterOptionsPresent = nuxt.options._layers.some(layer => existsSync(resolve(layer.config.srcDir, 'app/router.options.ts'))) + // Disable module (and use universal router) if pages dir do not exists or user has disabled it - if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) { + if ((nuxt.options.pages === false || (nuxt.options.pages !== true && !pagesDirs.some(dir => existsSync(dir)))) && !isRouterOptionsPresent) { addPlugin(resolve(distDir, 'app/plugins/router')) return } From f01594bf17521bd24b19e5be9e0c405c37129523 Mon Sep 17 00:00:00 2001 From: Benicio Cardozo Date: Fri, 14 Oct 2022 14:03:19 -0300 Subject: [PATCH 4/4] Update docs/content/2.guide/2.directory-structure/1.pages.md Co-authored-by: pooya parsa --- docs/content/2.guide/2.directory-structure/1.pages.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/2.guide/2.directory-structure/1.pages.md b/docs/content/2.guide/2.directory-structure/1.pages.md index 6dfcc289098..a49d0060c2a 100644 --- a/docs/content/2.guide/2.directory-structure/1.pages.md +++ b/docs/content/2.guide/2.directory-structure/1.pages.md @@ -10,7 +10,7 @@ head.title: "Pages" Nuxt provides a file-based routing to create routes within your web application using [Vue Router](https://router.vuejs.org) under the hood. ::alert{type="info"} -This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app) (unless you provide an [`router.options.ts`](/guide/directory-structure/pages#router-options), reducing your application's bundle size. +This directory is **optional**, meaning that [`vue-router`](https://router.vuejs.org) won't be included if you only use [app.vue](/guide/directory-structure/app) (unless you set `pages: true` in `nuxt.config` or have a [`app/router.options.ts`](/guide/directory-structure/pages#router-options)), reducing your application's bundle size. :: ## Usage