fix(docs): preserve hash anchor links

This commit is contained in:
ShadowArcanist
2026-06-17 22:50:16 +05:30
parent 71a397f76e
commit 13f04592bd
+16 -2
View File
@@ -1,4 +1,4 @@
import { createRootRoute, HeadContent, Outlet, Scripts } from '@tanstack/react-router';
import { createRootRoute, HeadContent, Link, Outlet, Scripts } from '@tanstack/react-router';
import { RootProvider } from 'fumadocs-ui/provider/tanstack';
import * as React from 'react';
import SearchDialog from '@/components/search';
@@ -116,7 +116,7 @@ function RootComponent() {
) : null}
</head>
<body className="flex min-h-screen flex-col">
<RootProvider search={{ SearchDialog }}>
<RootProvider components={{ Link: DocsLink }} search={{ SearchDialog }}>
<Outlet />
</RootProvider>
<Scripts />
@@ -124,3 +124,17 @@ function RootComponent() {
</html>
);
}
function DocsLink({
href = '#',
prefetch = true,
...props
}: React.AnchorHTMLAttributes<HTMLAnchorElement> & {
prefetch?: boolean;
}) {
if (href.startsWith('#')) {
return <a href={href} {...props} />;
}
return <Link to={href} preload={prefetch ? 'intent' : false} {...props} />;
}