Skip to content

Commit 28f1ed9

Browse files
authored
Fix canonical URL ending with "/" (#2586)
1 parent 568266b commit 28f1ed9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/gitbook/src/lib/links.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,14 @@ export function baseUrl(): string {
7979

8080
/**
8181
* Create an absolute href in the current content.
82+
* If it's the root URL, the trailing slash will be removed.
8283
*/
8384
export function absoluteHref(href: string, withHost: boolean = false): string {
8485
const base = withHost ? baseUrl() : basePath();
86+
if (href === '') {
87+
// Remove the trailing slash if it's the root URL
88+
return base.slice(0, -1);
89+
}
8590
return `${base}${href.startsWith('/') ? href.slice(1) : href}`;
8691
}
8792

0 commit comments

Comments
 (0)