diff --git a/packages/nuxt/src/app/components/utils.ts b/packages/nuxt/src/app/components/utils.ts index dbe8d23744..5995e333a8 100644 --- a/packages/nuxt/src/app/components/utils.ts +++ b/packages/nuxt/src/app/components/utils.ts @@ -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 } diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 956cf88c99..a6e43696a2 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -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 `` 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