Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(nuxt): only resolve initial route once #26519

Merged
merged 7 commits into from Apr 3, 2024
Prev Previous commit
fix: use isSamePath to compare paths
  • Loading branch information
danielroe committed Apr 3, 2024
commit 5e2ec034d91e352dbe2ca5b3fe9a6baacfc39939
6 changes: 3 additions & 3 deletions packages/nuxt/src/pages/runtime/plugins/router.ts
Expand Up @@ -9,7 +9,7 @@ import {
createWebHistory
} from '#vue-router'
import { createError } from 'h3'
import { isEqual, withoutBase } from 'ufo'
import { isEqual, isSamePath, withoutBase } from 'ufo'

import type { PageMeta } from '../composables'

Expand Down Expand Up @@ -112,7 +112,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
? nuxtApp.ssrContext!.url
: createCurrentLocation(routerBase, window.location, nuxtApp.payload.path)

// Allows suspending the route object until page navigation completes`
// Allows suspending the route object until page navigation completes
const _route = shallowRef(router.currentRoute.value)
const syncCurrentRoute = () => { _route.value = router.currentRoute.value }
nuxtApp.hook('page:finish', syncCurrentRoute)
Expand Down Expand Up @@ -251,7 +251,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
path: to.fullPath
}
})))
} else if (import.meta.server && to.redirectedFrom && to.fullPath !== initialURL) {
} else if (import.meta.server && to.fullPath !== initialURL && (to.redirectedFrom || !isSamePath(to.fullPath, initialURL))) {
await nuxtApp.runWithContext(() => navigateTo(to.fullPath || '/'))
}
})
Expand Down