From d874726ffb7911c99dff1253efff72c172dfeb37 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 9 Dec 2024 15:19:10 +0000 Subject: [PATCH] fix(nuxt): guard `window` access --- packages/nuxt/src/pages/runtime/validate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/runtime/validate.ts b/packages/nuxt/src/pages/runtime/validate.ts index 263eab3cdc..ef8998dbe7 100644 --- a/packages/nuxt/src/pages/runtime/validate.ts +++ b/packages/nuxt/src/pages/runtime/validate.ts @@ -29,7 +29,9 @@ export default defineNuxtRouteMiddleware(async (to) => { // We pretend to have navigated to the invalid route so // that the user can return to the previous page with // the back button. - window?.history.pushState({}, '', to.fullPath) + if (typeof window !== 'undefined') { + window.history.pushState({}, '', to.fullPath) + } }) // We stop the navigation immediately before it resolves // if there is no other route matching it.