fix(nuxt): compatible route object for custom external routes (#19261)

This commit is contained in:
Daniel Roe 2023-02-27 16:13:14 +01:00 committed by GitHub
parent 9e6fa9f7ba
commit f16cce8824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -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,

View File

@ -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)