diff --git a/.changeset/cool-jars-matter.md b/.changeset/cool-jars-matter.md new file mode 100644 index 000000000..ff0c934f3 --- /dev/null +++ b/.changeset/cool-jars-matter.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +fix href being empty in TOC diff --git a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx index 2ff3289d7..4875633ac 100644 --- a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx +++ b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx @@ -17,7 +17,11 @@ export async function PageDocumentItem(props: { context: GitBookSiteContext; }) { const { rootPages, page, context } = props; - const href = context.linker.toPathForPage({ pages: rootPages, page }); + let href = context.linker.toPathForPage({ pages: rootPages, page }); + // toPathForPage can returns an empty path, this will cause all links to point to the current page. + if (href === '') { + href = '/'; + } return (