feat: Add prefetching for links to improve performance
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 53s
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 53s
This commit is contained in:
parent
48a644b74a
commit
67f2ff697e
@ -1,4 +1,5 @@
|
||||
import { usePageContext } from "vike-react/usePageContext";
|
||||
import { prefetch } from "vike/client/router";
|
||||
import clsx from "clsx";
|
||||
|
||||
export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) {
|
||||
@ -7,6 +8,8 @@ export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { hr
|
||||
const isSameDomain = !(props.href.startsWith("http") || props.href.startsWith("mailto"));
|
||||
const isDownload = props.href.endsWith(".pdf") || props.href.endsWith(".zip");
|
||||
|
||||
const handleMouseEnter = () => prefetch(props.href);
|
||||
|
||||
return (
|
||||
<a
|
||||
{...props}
|
||||
@ -14,6 +17,7 @@ export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { hr
|
||||
className={clsx(isActive && "is-active", props.className)}
|
||||
{...(isDownload ? { download: true } : {})}
|
||||
{...(!isSameDomain || isDownload ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
||||
{...(isSameDomain ? { onMouseEnter: handleMouseEnter } : {})}
|
||||
>
|
||||
{props.children}
|
||||
</a>
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user