first commit
This commit is contained in:
35
components/DocContent.tsx
Normal file
35
components/DocContent.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { MouseEvent } from 'react';
|
||||
|
||||
interface DocContentProps {
|
||||
contentHtml: string;
|
||||
}
|
||||
|
||||
export function DocContent({ contentHtml }: DocContentProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const handleLinkClick = (e: MouseEvent<HTMLElement>) => {
|
||||
const target = e.target as HTMLElement;
|
||||
const anchor = target.closest('a');
|
||||
|
||||
if (anchor && anchor.href) {
|
||||
const url = new URL(anchor.href);
|
||||
|
||||
// If it's an internal link on the same origin
|
||||
if (url.origin === window.location.origin) {
|
||||
e.preventDefault();
|
||||
router.push(url.pathname + url.search + url.hash);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className="doc-article"
|
||||
onClick={handleLinkClick}
|
||||
dangerouslySetInnerHTML={{ __html: contentHtml }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user