Skip to content

Commit

Permalink
fix(shared): fix VPLink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 11, 2023
1 parent b1fd968 commit ce580d8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/shared/src/client/components/VPLink.ts
Expand Up @@ -4,7 +4,7 @@ import { h } from "vue";
import type { NavigationFailure } from "vue-router";
import { useRouter } from "vue-router";

import { inferRouteLink } from "../../shared/index.js";
import { inferRouteLink, startsWith } from "../../shared/index.js";
import { guardEvent } from "../utils/index.js";

export interface VPLinkProps extends Record<string, unknown> {
Expand All @@ -19,6 +19,9 @@ export const VPLink: FunctionalComponent<
}
> = ({ to = "", class: className = "", ...attrs }, { slots }) => {
const router = useRouter();

const inferPath = inferRouteLink(to);

const navigate = (
event: MouseEvent = {} as MouseEvent,
): Promise<void | NavigationFailure> =>
Expand All @@ -29,7 +32,7 @@ export const VPLink: FunctionalComponent<
{
...attrs,
class: ["vp-link", className],
href: withBase(inferRouteLink(to)),
href: startsWith(inferPath, "/") ? withBase(inferPath) : inferPath,
onClick: navigate,
},
slots.default?.(),
Expand Down

0 comments on commit ce580d8

Please sign in to comment.