mirror of https://github.com/buster-so/buster.git
prevent default on link click
This commit is contained in:
parent
81a59370d4
commit
2627cedf03
|
@ -256,10 +256,22 @@ const DropdownMenuLink: React.FC<{
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!link) return <div className={className}>{content}</div>;
|
if (!link)
|
||||||
|
return (
|
||||||
|
<div className={className} onClick={(e) => e.stopPropagation()}>
|
||||||
|
{content}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link className={className} href={link} target={isExternal ? '_blank' : '_self'}>
|
<Link
|
||||||
|
className={className}
|
||||||
|
href={link}
|
||||||
|
target={isExternal ? '_blank' : '_self'}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}}>
|
||||||
{content}
|
{content}
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,14 +44,26 @@ export const PreventNavigation: React.FC<PreventNavigationProps> = React.memo(
|
||||||
* @param e The triggered event.
|
* @param e The triggered event.
|
||||||
*/
|
*/
|
||||||
const handleClick = useMemoizedFn((event: MouseEvent) => {
|
const handleClick = useMemoizedFn((event: MouseEvent) => {
|
||||||
const target = event.target as HTMLAnchorElement;
|
let target = event.target as HTMLElement;
|
||||||
|
let href: string | null = null;
|
||||||
|
|
||||||
|
// Traverse up the DOM tree looking for an anchor tag with href
|
||||||
|
while (target && !href) {
|
||||||
|
if (target instanceof HTMLAnchorElement && target.href) {
|
||||||
|
href = target.href;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
target = target.parentElement as HTMLElement;
|
||||||
|
}
|
||||||
|
|
||||||
if (isDirty) {
|
if (isDirty) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
console.log(href);
|
||||||
|
|
||||||
confirmationFn.current = () => {
|
confirmationFn.current = () => {
|
||||||
router.push(target.href);
|
if (href) router.push(href);
|
||||||
};
|
};
|
||||||
|
|
||||||
setLeavingPage(true);
|
setLeavingPage(true);
|
||||||
|
|
Loading…
Reference in New Issue