chore: router improvements (#139)

This commit is contained in:
Sébastien Chopin 2021-02-02 17:42:48 +01:00 committed by GitHub
parent 9be282623c
commit b04e212ebc
4 changed files with 18 additions and 7 deletions

View File

@ -0,0 +1,6 @@
<template>
<div>
<!-- TODO: Move this page to @nuxt/nice -->
404 | Page Not Found
</div>
</template>

View File

@ -13,11 +13,6 @@ import routes from '~build/routes'
export default <Plugin> function router (nuxt) {
const { app } = nuxt
// TODO: move this outside this plugin
if (!routes.length) {
return
}
app.component('NuxtPage', NuxtPage)
app.component('NuxtLink', RouterLink)

View File

@ -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}' */)}`
}

View File

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