diff --git a/packages/nuxt/src/app/components/nuxt-link.ts b/packages/nuxt/src/app/components/nuxt-link.ts index f0223ec037..14d25a1cdd 100644 --- a/packages/nuxt/src/app/components/nuxt-link.ts +++ b/packages/nuxt/src/app/components/nuxt-link.ts @@ -1,7 +1,7 @@ import type { PropType, DefineComponent, ComputedRef } from 'vue' import { defineComponent, h, ref, resolveComponent, computed, onMounted, onBeforeUnmount } from 'vue' import type { RouteLocationRaw } from 'vue-router' -import { hasProtocol } from 'ufo' +import { hasProtocol, parseQuery, parseURL } from 'ufo' import { preloadRouteComponents } from '../composables/preload' import { onNuxtReady } from '../composables/ready' @@ -250,10 +250,28 @@ export function defineNuxtLink (options: NuxtLinkOptions) { if (!slots.default) { return null } + return slots.default({ href, navigate, - route: router.resolve(href!), + get route () { + if (!href) { return undefined } + + const url = parseURL(href) + return { + path: url.pathname, + fullPath: url.pathname, + get query () { return parseQuery(url.search) }, + hash: url.hash, + // stub properties for compat with vue-router + params: {}, + name: undefined, + matched: [], + redirectedFrom: undefined, + meta: {}, + href + } + }, rel, target, isExternal: isExternal.value, diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 330f039ce3..141f543cb7 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => { it('default server bundle size', async () => { stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect(stats.server.totalBytes).toBeLessThan(92100) + expect(stats.server.totalBytes).toBeLessThan(92700) const modules = await analyzeSizes('node_modules/**/*', serverDir) expect(modules.totalBytes).toBeLessThan(2710200)