Properly redirect to the root page (#3369)

Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
This commit is contained in:
conico974
2025-06-20 19:15:21 +02:00
committed by GitHub
parent 4721403986
commit 7fb9004b43
2 changed files with 8 additions and 5 deletions
+6 -4
View File
@@ -35,8 +35,9 @@ describe('toPathInSpace', () => {
expect(variantInSection.toPathInSpace('some/path/')).toBe('/section/variant/some/path');
});
it('should not add a trailing slash', () => {
expect(root.toPathInSpace('')).toBe('');
it('should not add an unnecessary trailing slash', () => {
// The index page should not be an empty path
expect(root.toPathInSpace('')).toBe('/');
expect(variantInSection.toPathInSpace('')).toBe('/section/variant');
});
});
@@ -52,8 +53,9 @@ describe('toPathInSite', () => {
expect(siteGitBookIO.toPathInSite('some/path/')).toBe('/sitename/some/path');
});
it('should not add a trailing slash', () => {
expect(root.toPathInSite('')).toBe('');
it('should not add an unnecessary trailing slash', () => {
// The index page should not be an empty path
expect(root.toPathInSite('')).toBe('/');
expect(siteGitBookIO.toPathInSite('')).toBe('/sitename');
});
});
+2 -1
View File
@@ -128,7 +128,8 @@ export function createLinker(
function joinPaths(prefix: string, path: string): string {
const prefixPath = prefix.endsWith('/') ? prefix : `${prefix}/`;
const suffixPath = path.startsWith('/') ? path.slice(1) : path;
return removeTrailingSlash(prefixPath + suffixPath);
const pathWithoutTrailingSlash = removeTrailingSlash(prefixPath + suffixPath);
return pathWithoutTrailingSlash === '' ? '/' : pathWithoutTrailingSlash;
}
function removeTrailingSlash(path: string): string {