Skip to content

Commit 4ca1ab7

Browse files
committedFeb 22, 2024
fix(nuxt): set to.name to be undefined rather than deleting entirely
1 parent ba6a413 commit 4ca1ab7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed
 

‎packages/nuxt/src/app/components/nuxt-link.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface NuxtLinkProps extends Omit<RouterLinkProps, 'to'> {
8888
noPrefetch?: boolean
8989
}
9090

91-
/*@__NO_SIDE_EFFECTS__*/
91+
/*@__NO_SIDE_EFFECTS__*/
9292
export function defineNuxtLink (options: NuxtLinkOptions) {
9393
const componentName = options.componentName || 'NuxtLink'
9494

@@ -100,7 +100,6 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
100100

101101
function resolveTrailingSlashBehavior (to: string, resolve: Router['resolve']): string
102102
function resolveTrailingSlashBehavior (to: RouteLocationRaw, resolve: Router['resolve']): Exclude<RouteLocationRaw, string>
103-
function resolveTrailingSlashBehavior (to: undefined, resolve: Router['resolve']): undefined
104103
function resolveTrailingSlashBehavior (to: RouteLocationRaw | undefined, resolve: Router['resolve']): RouteLocationRaw | RouteLocation | undefined {
105104
if (!to || (options.trailingSlash !== 'append' && options.trailingSlash !== 'remove')) {
106105
return to
@@ -117,6 +116,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
117116
path: applyTrailingSlashBehavior(path, options.trailingSlash)
118117
}
119118

119+
// named routes would otherwise always override trailing slash behavior
120120
if ('name' in resolvedPath) {
121121
delete resolvedPath.name
122122
}
@@ -332,8 +332,8 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
332332
const href = typeof to.value === 'object'
333333
? router.resolve(to.value)?.href ?? null
334334
: (to.value && !props.external && !isAbsoluteUrl.value)
335-
? resolveTrailingSlashBehavior(joinURL(config.app.baseURL, to.value), router.resolve) as string
336-
: to.value || null
335+
? resolveTrailingSlashBehavior(joinURL(config.app.baseURL, to.value), router.resolve) as string
336+
: to.value || null
337337

338338
// Resolves `target` value
339339
const target = props.target || null

‎packages/nuxt/src/pages/runtime/plugins/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
239239
try {
240240
const to = router.resolve(initialURL)
241241
// #4920, #4982
242-
if ('name' in to) { delete to.name }
242+
if ('name' in to) { to.name = undefined }
243243
await router.replace({
244244
...to,
245245
force: true

0 commit comments

Comments
 (0)
Please sign in to comment.