Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt3): return error page on blocked initial navigation #3201

Merged
merged 7 commits into from Feb 14, 2022
7 changes: 6 additions & 1 deletion packages/nuxt3/src/pages/runtime/router.ts
Expand Up @@ -105,7 +105,12 @@ export default defineNuxtPlugin((nuxtApp) => {
if (process.server) {
router.push(nuxtApp.ssrContext.url)

router.afterEach((to) => {
router.afterEach((to, from, failure) => {
if (failure) {
// TODO: https://github.com/nuxt/framework/discussions/559
danielroe marked this conversation as resolved.
Show resolved Hide resolved
nuxtApp.ssrContext.res.statusCode = 401
danielroe marked this conversation as resolved.
Show resolved Hide resolved
nuxtApp.ssrContext.res.end()
danielroe marked this conversation as resolved.
Show resolved Hide resolved
}
if (to.fullPath !== nuxtApp.ssrContext.url) {
nuxtApp.ssrContext.res.setHeader('Location', to.fullPath)
}
Expand Down