Add option to use onMouseDown in Link rather than onClick #66121
Jagatpratap
started this conversation in
Ideas
Replies: 1 comment
-
Heres a simple component which does the trick. Taken from here, without the image prefetching stuff: https://github.com/ethanniser/NextFaster/blob/main/src/components/ui/link.tsx import NextLink from "next/link";
import { useRouter } from "next/navigation";
export const Link: typeof NextLink = (({ children, ...props }) => {
const router = useRouter();
return (
<NextLink
prefetch={true}
onMouseDown={(e) => {
const url = new URL(String(props.href as string), window.location.href);
if (
url.origin === window.location.origin &&
e.button === 0 &&
!e.altKey &&
!e.ctrlKey &&
!e.metaKey &&
!e.shiftKey
) {
e.preventDefault();
router.push(String(props.href as string));
}
}}
{...props}
>
{children}
</NextLink>
);
}) as typeof NextLink; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
This make ui super smooth
Proposal
I am interested to contributing. Easy to implement.
Beta Was this translation helpful? Give feedback.
All reactions