Compare commits

...

4 Commits

Author SHA1 Message Date
Ryota Watanabe d355e4bdd4
Merge 0e4d0d5d63 into e644960794 2024-09-20 14:31:09 +00:00
Ryota Watanabe 0e4d0d5d63
Merge branch 'main' into fix/avoid-show-error-before-middleware 2024-09-20 23:31:06 +09:00
autofix-ci[bot] 0ef7f8d46f
[autofix.ci] apply automated fixes 2024-09-20 14:30:07 +00:00
wattanx a340ebd13d fix: avoid throwing a 404 error before the middleware is executed 2024-09-20 23:27:28 +09:00
1 changed files with 15 additions and 10 deletions

View File

@ -148,16 +148,8 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
if (import.meta.server && failure?.type === 4 /* ErrorTypes.NAVIGATION_ABORTED */) {
return
}
if (to.matched.length === 0) {
await nuxtApp.runWithContext(() => showError(createError({
statusCode: 404,
fatal: false,
statusMessage: `Page not found: ${to.fullPath}`,
data: {
path: to.fullPath,
},
})))
} else if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) {
if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) {
await nuxtApp.runWithContext(() => navigateTo(to.fullPath || '/'))
}
})
@ -252,6 +244,19 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
await nuxtApp.callHook('page:loading:end')
})
router.afterEach(async (to, _from) => {
if (to.matched.length === 0) {
await nuxtApp.runWithContext(() => showError(createError({
statusCode: 404,
fatal: false,
statusMessage: `Page not found: ${to.fullPath}`,
data: {
path: to.fullPath,
},
})))
}
})
nuxtApp.hooks.hookOnce('app:created', async () => {
try {
// #4920, #4982