@@ -88,7 +88,7 @@ export interface NuxtLinkProps extends Omit<RouterLinkProps, 'to'> {
88
88
noPrefetch ?: boolean
89
89
}
90
90
91
- /*@__NO_SIDE_EFFECTS__ */
91
+ /*@__NO_SIDE_EFFECTS__ */
92
92
export function defineNuxtLink ( options : NuxtLinkOptions ) {
93
93
const componentName = options . componentName || 'NuxtLink'
94
94
@@ -100,7 +100,8 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
100
100
101
101
function resolveTrailingSlashBehavior ( to : string , resolve : Router [ 'resolve' ] ) : string
102
102
function resolveTrailingSlashBehavior ( to : RouteLocationRaw , resolve : Router [ 'resolve' ] ) : Exclude < RouteLocationRaw , string >
103
- function resolveTrailingSlashBehavior ( to : RouteLocationRaw , resolve : Router [ 'resolve' ] ) : RouteLocationRaw | RouteLocation {
103
+ function resolveTrailingSlashBehavior ( to : undefined , resolve : Router [ 'resolve' ] ) : undefined
104
+ function resolveTrailingSlashBehavior ( to : RouteLocationRaw | undefined , resolve : Router [ 'resolve' ] ) : RouteLocationRaw | RouteLocation | undefined {
104
105
if ( ! to || ( options . trailingSlash !== 'append' && options . trailingSlash !== 'remove' ) ) {
105
106
return to
106
107
}
@@ -109,13 +110,18 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
109
110
return applyTrailingSlashBehavior ( to , options . trailingSlash )
110
111
}
111
112
112
- const path = 'path' in to ? to . path : resolve ( to ) . path
113
+ const path = 'path' in to && to . path !== undefined ? to . path : resolve ( to ) . path
113
114
114
- return {
115
+ const resolvedPath = {
115
116
...to ,
116
- name : undefined , // named routes would otherwise always override trailing slash behavior
117
117
path : applyTrailingSlashBehavior ( path , options . trailingSlash )
118
118
}
119
+
120
+ if ( 'name' in resolvedPath ) {
121
+ delete resolvedPath . name
122
+ }
123
+
124
+ return resolvedPath
119
125
}
120
126
121
127
return defineComponent ( {
@@ -326,8 +332,8 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
326
332
const href = typeof to . value === 'object'
327
333
? router . resolve ( to . value ) ?. href ?? null
328
334
: ( to . value && ! props . external && ! isAbsoluteUrl . value )
329
- ? resolveTrailingSlashBehavior ( joinURL ( config . app . baseURL , to . value ) , router . resolve ) as string
330
- : to . value || null
335
+ ? resolveTrailingSlashBehavior ( joinURL ( config . app . baseURL , to . value ) , router . resolve ) as string
336
+ : to . value || null
331
337
332
338
// Resolves `target` value
333
339
const target = props . target || null
0 commit comments