Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ useShortcuts({
class="border-none"
variant="button-secondary"
:to="link.to"
:name="link.name"
:aria-keyshortcuts="link.keyshortcut"
>
{{ link.label }}
Expand Down
28 changes: 26 additions & 2 deletions app/components/Link/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const props = withDefaults(
/** Link destination (internal or external URL) */
to?: NuxtLinkProps['to']

/**
* Link name used to trigger package-aware routing for compare links
*/
name?: string

Comment thread
btea marked this conversation as resolved.
/** always use `to` instead of `href` */
href?: never

Expand Down Expand Up @@ -69,8 +74,27 @@ const isButtonMedium = computed(() => props.size === 'md' && !isLink.value)
const slots = useSlots()
const iconOnly = computed(() => !!props.classicon && !slots.default)
const keyboardShortcutsEnabled = useKeyboardShortcuts()
</script>

const { packageName } = usePackageRoute()

const linkTo = computed(() => {
if (props.name?.toLocaleLowerCase() !== 'compare' || !packageName.value) {
return props.to
}
// On a package page (/package/:name), carry the current package name to the compare page
if (typeof props.to !== 'object' || props.to === null) {
return props.to
}
const to = { ...props.to } as Record<string, any>
return {
...to,
query: {
...to.query,
packages: packageName.value,
},
}
})
</script>
<template>
<span
v-if="disabled"
Expand Down Expand Up @@ -121,7 +145,7 @@ const keyboardShortcutsEnabled = useKeyboardShortcuts()
'text-bg bg-fg hover:(bg-fg/50 text-accent) focus-visible:(bg-fg/50) aria-current:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':
variant === 'button-primary',
}"
:to="to"
:to="linkTo"
:aria-keyshortcuts="keyboardShortcutsEnabled ? ariaKeyshortcuts : undefined"
:target="isLinkExternal ? '_blank' : undefined"
>
Expand Down
Loading