From b04e212ebc9f57bfc609b02e798215704020fa36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Tue, 2 Feb 2021 17:42:48 +0100 Subject: [PATCH] chore: router improvements (#139) --- packages/nuxt3/src/app/pages/404.vue | 6 ++++++ packages/nuxt3/src/app/plugins/router/index.ts | 5 ----- packages/nuxt3/src/builder/app.ts | 12 +++++++++++- packages/nuxt3/src/config/options.ts | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 packages/nuxt3/src/app/pages/404.vue diff --git a/packages/nuxt3/src/app/pages/404.vue b/packages/nuxt3/src/app/pages/404.vue new file mode 100644 index 0000000000..da12ddee66 --- /dev/null +++ b/packages/nuxt3/src/app/pages/404.vue @@ -0,0 +1,6 @@ + diff --git a/packages/nuxt3/src/app/plugins/router/index.ts b/packages/nuxt3/src/app/plugins/router/index.ts index 0815b3c2ca..81809a660f 100644 --- a/packages/nuxt3/src/app/plugins/router/index.ts +++ b/packages/nuxt3/src/app/plugins/router/index.ts @@ -13,11 +13,6 @@ import routes from '~build/routes' export default function router (nuxt) { const { app } = nuxt - // TODO: move this outside this plugin - if (!routes.length) { - return - } - app.component('NuxtPage', NuxtPage) app.component('NuxtLink', RouterLink) diff --git a/packages/nuxt3/src/builder/app.ts b/packages/nuxt3/src/builder/app.ts index 3ffd7b3981..91e2612d9a 100644 --- a/packages/nuxt3/src/builder/app.ts +++ b/packages/nuxt3/src/builder/app.ts @@ -43,6 +43,16 @@ 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: [] + }) + } // TODO: Hook to extend routes app.templates.routes = serializeRoutes(app.routes) @@ -69,7 +79,7 @@ function formatRoute (route: NuxtRoute) { name: route.name, path: route.path, children: route.children.map(formatRoute), - // TODO: avoid exposing to prod + // TODO: avoid exposing to prod, using process.env.NODE_ENV ? __file: route.file, component: `{() => import('${route.file}' /* webpackChunkName: '${route.name}' */)}` } diff --git a/packages/nuxt3/src/config/options.ts b/packages/nuxt3/src/config/options.ts index 76906dfc89..f83586d6e7 100644 --- a/packages/nuxt3/src/config/options.ts +++ b/packages/nuxt3/src/config/options.ts @@ -299,7 +299,7 @@ function normalizeConfig (_options: CliConfiguration) { // Append ignorePrefix glob to ignore if (typeof options.ignorePrefix === 'string') { - options.ignore.push(`**/${options.ignorePrefix}*.*`) + options.ignore.push(`${options.ignorePrefix}*`) } // Compression middleware legacy