From d63b28303ece59df69f79def167aea97bc7ed5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Wed, 17 Feb 2021 15:29:15 +0100 Subject: [PATCH] fix: don't display 404 page if no pages/ --- packages/nuxt3/src/app/_templates/routes.js | 2 +- packages/nuxt3/src/builder/app.ts | 24 +++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/nuxt3/src/app/_templates/routes.js b/packages/nuxt3/src/app/_templates/routes.js index 1d1476ecee..c78721488d 100644 --- a/packages/nuxt3/src/app/_templates/routes.js +++ b/packages/nuxt3/src/app/_templates/routes.js @@ -1,2 +1,2 @@ // TODO: Use webpack-virtual-modules -export default <%= app.templates.routes %> +export default <%= app.templates.routes || '[]' %> diff --git a/packages/nuxt3/src/builder/app.ts b/packages/nuxt3/src/builder/app.ts index 91e2612d9a..9b523e7631 100644 --- a/packages/nuxt3/src/builder/app.ts +++ b/packages/nuxt3/src/builder/app.ts @@ -43,18 +43,20 @@ export async function createApp ( if (app.pages) { app.routes.push(...(await resolvePagesRoutes(builder, app))) } - // Add 404 page is not added - const page404 = app.routes.find(route => route.name === '404') - if (!page404) { - app.routes.push({ - name: '404', - path: '/:catchAll(.*)*', - file: resolve(nuxt.options.appDir, 'pages/404.vue'), - children: [] - }) + if (app.routes.length) { + // Add 404 page is not added + const page404 = app.routes.find(route => route.name === '404') + if (!page404) { + app.routes.push({ + name: '404', + path: '/:catchAll(.*)*', + file: resolve(nuxt.options.appDir, 'pages/404.vue'), + children: [] + }) + } + // TODO: Hook to extend routes + app.templates.routes = serializeRoutes(app.routes) } - // TODO: Hook to extend routes - app.templates.routes = serializeRoutes(app.routes) // Fallback app.main if (!app.main && app.routes.length) {