Skip to content

Commit b3a7ad6

Browse files
conico974Nicolas Dorseuil
and
Nicolas Dorseuil
authored
Fix href being empty in TOC (#3269)
Co-authored-by: Nicolas Dorseuil <[email protected]>
1 parent 2932077 commit b3a7ad6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/cool-jars-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
fix href being empty in TOC

packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export async function PageDocumentItem(props: {
1717
context: GitBookSiteContext;
1818
}) {
1919
const { rootPages, page, context } = props;
20-
const href = context.linker.toPathForPage({ pages: rootPages, page });
20+
let href = context.linker.toPathForPage({ pages: rootPages, page });
21+
// toPathForPage can returns an empty path, this will cause all links to point to the current page.
22+
if (href === '') {
23+
href = '/';
24+
}
2125

2226
return (
2327
<li className="flex flex-col">

0 commit comments

Comments
 (0)