UI: Fix relative file href with hash

This commit is contained in:
Fuma Nama
2025-04-21 16:35:14 +08:00
parent 17a80922db
commit ea0f4684aa
3 changed files with 14 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-ui': patch
---
Fix relative file href with hash
@@ -21,7 +21,9 @@ fumadocs-ui fumadocs-core
### 2. Content Source
Fumadocs supports different content sources, there's how you configure Fumadocs MDX:
Fumadocs supports different content sources, including Fumadocs MDX and [Content Collections](/docs/headless/content-collections).
Fumadocs MDX is our official content source, you can configure it with:
```package-install
fumadocs-mdx @types/mdx
+6 -1
View File
@@ -18,7 +18,12 @@ export function createRelativeLink(
// resolve relative href
if (href && href.startsWith('.')) {
const target = source.getPageByHref(href, { dir: page.file.dirname });
if (target) href = target.page.url;
if (target) {
href = target.hash
? `${target.page.url}#${target.hash}`
: target.page.url;
}
}
return <OverrideLink href={href} {...props} />;