Skip to content

Commit

Permalink
fix(nuxt): set to.name to be undefined rather than deleting entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 22, 2024
1 parent ba6a413 commit 4ca1ab7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/nuxt/src/app/components/nuxt-link.ts
Expand Up @@ -88,7 +88,7 @@ export interface NuxtLinkProps extends Omit<RouterLinkProps, 'to'> {
noPrefetch?: boolean
}

/*@__NO_SIDE_EFFECTS__*/
/*@__NO_SIDE_EFFECTS__*/
export function defineNuxtLink (options: NuxtLinkOptions) {
const componentName = options.componentName || 'NuxtLink'

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

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

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

// Resolves `target` value
const target = props.target || null
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/pages/runtime/plugins/router.ts
Expand Up @@ -239,7 +239,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
try {
const to = router.resolve(initialURL)
// #4920, #4982
if ('name' in to) { delete to.name }
if ('name' in to) { to.name = undefined }
await router.replace({
...to,
force: true
Expand Down

0 comments on commit 4ca1ab7

Please sign in to comment.