Skip to content

Commit

Permalink
fix(client): support html attrs for VPLink (#1483)
Browse files Browse the repository at this point in the history
Co-authored-by: Xinyu Liu <meteor.lxy@foxmail.com>
  • Loading branch information
Mister-Hope and meteorlxy committed Feb 4, 2024
1 parent 57dd7fc commit bfadfcf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/client/src/components/VPLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from 'vue'
import type { FunctionalComponent, VNode } from 'vue'
import type { FunctionalComponent, HTMLAttributes, VNode } from 'vue'
import { useRouter } from 'vue-router'
import { withBase } from '../helpers/index.js'
import { resolveRoutePath } from '../router/index.js'
Expand All @@ -23,7 +23,7 @@ const guardEvent = (event: MouseEvent): boolean | void => {
return true
}

export interface VPLinkProps {
export interface VPLinkProps extends HTMLAttributes {
to: string
}

Expand All @@ -33,7 +33,7 @@ export const VPLink: FunctionalComponent<
{
default: () => string | VNode | (string | VNode)[]
}
> = ({ to = '' }, { slots }) => {
> = ({ to = '', ...attrs }, { slots }) => {
const router = useRouter()
const path = withBase(resolveRoutePath(to))

Expand All @@ -42,6 +42,7 @@ export const VPLink: FunctionalComponent<
{
class: 'vp-link',
href: path,
...attrs,
onClick: (event: MouseEvent = {} as MouseEvent) => {
guardEvent(event) ? router.push(to).catch() : Promise.resolve()
},
Expand Down

0 comments on commit bfadfcf

Please sign in to comment.