Fix 404 for embed root page

Going to `/~gitbook/embed/page/` should load the space's root page, but returns a 404 instead. This fixes that.
This commit is contained in:
Zeno Kapitein
2025-11-18 19:38:20 +01:00
parent 854e612e5d
commit 79ce105caa
4 changed files with 9 additions and 9 deletions
+5 -3
View File
@@ -19,7 +19,7 @@ export type RouteLayoutParams = {
};
export type RouteParams = RouteLayoutParams & {
pagePath: string;
pagePath?: string[];
};
/**
@@ -80,8 +80,10 @@ export async function getDynamicSiteContext(params: RouteLayoutParams) {
* Get the decoded page path from the params.
*/
export function getPagePathFromParams(params: RouteParams) {
const decoded = decodeURIComponent(params.pagePath);
return decoded;
if (!params.pagePath || params.pagePath.length === 0) {
return '';
}
return params.pagePath.map((part) => decodeURIComponent(part)).join('/');
}
function getSiteURLFromParams(params: RouteLayoutParams) {
+4 -6
View File
@@ -589,12 +589,10 @@ function encodePathInSiteContent(rawPathname: string): {
return { pathname, routeType: 'static' };
}
// If the pathname is an embedded page
const embedPage = pathname.match(/^~gitbook\/embed\/page\/(\S+)$/);
if (embedPage) {
return {
pathname: `~gitbook/embed/page/${encodeURIComponent(embedPage[1]!)}`,
};
// If the pathname is an embedded page, let the optional catch-all route [[...pagePath]] handle it
// This naturally supports both empty paths (~gitbook/embed/page) and paths with segments
if (pathname.match(/^~gitbook\/embed\/page(\/.*)?$/)) {
return { pathname };
}
switch (pathname) {