diff --git a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts index b3818e90f2..f954244965 100644 --- a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts +++ b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts @@ -37,13 +37,24 @@ export default defineComponent({ const router = useRouter() globalMiddleware.unshift(indicator.start) + router.onError(() => { + indicator.finish() + }) router.beforeResolve((to, from) => { if (to === from || to.matched.every((comp, index) => comp.components && comp.components?.default === from.matched[index]?.components?.default)) { indicator.finish() } }) + + router.afterEach((_to, _from, failure) => { + if (failure) { + indicator.finish() + } + }) + nuxtApp.hook('page:finish', indicator.finish) nuxtApp.hook('vue:error', indicator.finish) + onBeforeUnmount(() => { const index = globalMiddleware.indexOf(indicator.start) if (index >= 0) { diff --git a/packages/nuxt/src/pages/runtime/plugins/router.ts b/packages/nuxt/src/pages/runtime/plugins/router.ts index 4efeb84616..9d63a966e6 100644 --- a/packages/nuxt/src/pages/runtime/plugins/router.ts +++ b/packages/nuxt/src/pages/runtime/plugins/router.ts @@ -175,7 +175,10 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({ return false } } - if (result || result === false) { return result } + + if (result || result === false) { + return result + } } } }) diff --git a/test/basic.test.ts b/test/basic.test.ts index 60a94954f6..7b28c950e4 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -168,6 +168,15 @@ describe('pages', () => { await expectNoClientErrors('/not-found') }) + it('expect no loading indicator on middleware abortNavigation', async () => { + const { page } = await renderPage('/') + await page.waitForLoadState('networkidle') + await page.locator('#middleware-abort-non-fatal').click() + expect(await page.locator('#lodagin-indicator').all()).toHaveLength(0) + await page.locator('#middleware-abort-non-fatal-error').click() + expect(await page.locator('#lodagin-indicator').all()).toHaveLength(0) + }) + it('should render correctly when loaded on a different path', async () => { const page = await createPage('/proxy') diff --git a/test/fixtures/basic/extends/node_modules/foo/layouts/default.vue b/test/fixtures/basic/extends/node_modules/foo/layouts/default.vue index 1627862189..671b27180f 100644 --- a/test/fixtures/basic/extends/node_modules/foo/layouts/default.vue +++ b/test/fixtures/basic/extends/node_modules/foo/layouts/default.vue @@ -1,5 +1,6 @@