fix(nuxt): don't show transition on initial page load (#24935)

This commit is contained in:
Bernhard Berger 2024-01-02 11:00:47 +01:00 committed by GitHub
parent 4dd87f6e28
commit 160208009e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import type { Component, RendererNode } from 'vue'
import { isString, isPromise, isArray, isObject } from '@vue/shared'
import destr from 'destr'
import type { RouteLocationNormalized } from '#vue-router'
// @ts-expect-error virtual file
import { START_LOCATION } from '#build/pages'
/**
* Internal utility
@ -29,7 +31,7 @@ function generateRouteKey (route: RouteLocationNormalized) {
* return true if the route has been changed with a page change during navigation
*/
export function isChangingPage (to: RouteLocationNormalized, from: RouteLocationNormalized) {
if (to === from) { return false }
if (to === from || from === START_LOCATION) { return false }
// If route keys are different then it will result in a rerender
if (generateRouteKey(to) !== generateRouteKey(from)) { return true }

View File

@ -90,7 +90,10 @@ export default defineNuxtModule({
addPlugin(resolve(distDir, 'app/plugins/router'))
addTemplate({
filename: 'pages.mjs',
getContents: () => 'export { useRoute } from \'#app\''
getContents: () => [
'export { useRoute } from \'#app/composables/router\'',
'export const START_LOCATION = Symbol(\'router:start-location\')'
].join('\n')
})
addComponent({
name: 'NuxtPage',
@ -371,7 +374,7 @@ export default defineNuxtModule({
// Add vue-router import for `<NuxtLayout>` integration
addTemplate({
filename: 'pages.mjs',
getContents: () => 'export { useRoute } from \'vue-router\''
getContents: () => 'export { START_LOCATION, useRoute } from \'vue-router\''
})
// Optimize vue-router to ensure we share the same injection symbol