mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): abort navigation when updating window.location
(#21521)
This commit is contained in:
parent
1ab19b916a
commit
187230b0c5
@ -148,8 +148,9 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
|||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
const nuxtApp = useNuxtApp()
|
||||||
|
|
||||||
if (process.server) {
|
if (process.server) {
|
||||||
const nuxtApp = useNuxtApp()
|
|
||||||
if (nuxtApp.ssrContext) {
|
if (nuxtApp.ssrContext) {
|
||||||
const fullPath = typeof to === 'string' || isExternal ? toPath : router.resolve(to).fullPath || '/'
|
const fullPath = typeof to === 'string' || isExternal ? toPath : router.resolve(to).fullPath || '/'
|
||||||
const location = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, fullPath)
|
const location = isExternal ? toPath : joinURL(useRuntimeConfig().app.baseURL, fullPath)
|
||||||
@ -183,6 +184,16 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
|||||||
} else {
|
} else {
|
||||||
location.href = toPath
|
location.href = toPath
|
||||||
}
|
}
|
||||||
|
// Within in a Nuxt route middleware handler
|
||||||
|
if (inMiddleware) {
|
||||||
|
// Abort navigation when app is hydrated
|
||||||
|
if (!nuxtApp.isHydrating) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// When app is hydrating (i.e. on page load), we don't want to abort navigation as
|
||||||
|
// it would lead to a 404 error / page that's blinking before location changes.
|
||||||
|
return new Promise(() => {})
|
||||||
|
}
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
|
|||||||
|
|
||||||
it('default server bundle size', async () => {
|
it('default server bundle size', async () => {
|
||||||
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
||||||
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"61.9k"')
|
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"62.0k"')
|
||||||
|
|
||||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||||
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2295k"')
|
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2295k"')
|
||||||
|
Loading…
Reference in New Issue
Block a user