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