fix: don't display 404 page if no pages/

This commit is contained in:
Sébastien Chopin 2021-02-17 15:29:15 +01:00
parent b4251b1389
commit d63b28303e
2 changed files with 14 additions and 12 deletions

View File

@ -1,2 +1,2 @@
// TODO: Use webpack-virtual-modules
export default <%= app.templates.routes %>
export default <%= app.templates.routes || '[]' %>

View File

@ -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) {