Skip to content

Commit 7fb9004

Browse files
conico974Nicolas Dorseuil
andauthored
Properly redirect to the root page (#3369)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
1 parent 4721403 commit 7fb9004

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/gitbook-v2/src/lib/links.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ describe('toPathInSpace', () => {
3535
expect(variantInSection.toPathInSpace('some/path/')).toBe('/section/variant/some/path');
3636
});
3737

38-
it('should not add a trailing slash', () => {
39-
expect(root.toPathInSpace('')).toBe('');
38+
it('should not add an unnecessary trailing slash', () => {
39+
// The index page should not be an empty path
40+
expect(root.toPathInSpace('')).toBe('/');
4041
expect(variantInSection.toPathInSpace('')).toBe('/section/variant');
4142
});
4243
});
@@ -52,8 +53,9 @@ describe('toPathInSite', () => {
5253
expect(siteGitBookIO.toPathInSite('some/path/')).toBe('/sitename/some/path');
5354
});
5455

55-
it('should not add a trailing slash', () => {
56-
expect(root.toPathInSite('')).toBe('');
56+
it('should not add an unnecessary trailing slash', () => {
57+
// The index page should not be an empty path
58+
expect(root.toPathInSite('')).toBe('/');
5759
expect(siteGitBookIO.toPathInSite('')).toBe('/sitename');
5860
});
5961
});

packages/gitbook-v2/src/lib/links.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export function createLinker(
128128
function joinPaths(prefix: string, path: string): string {
129129
const prefixPath = prefix.endsWith('/') ? prefix : `${prefix}/`;
130130
const suffixPath = path.startsWith('/') ? path.slice(1) : path;
131-
return removeTrailingSlash(prefixPath + suffixPath);
131+
const pathWithoutTrailingSlash = removeTrailingSlash(prefixPath + suffixPath);
132+
return pathWithoutTrailingSlash === '' ? '/' : pathWithoutTrailingSlash;
132133
}
133134

134135
function removeTrailingSlash(path: string): string {

0 commit comments

Comments
 (0)