Compare commits

...

1 Commits

Author SHA1 Message Date
Zeno Kapitein 79ce105caa 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.
2025-11-18 19:38:20 +01:00
4 changed files with 9 additions and 9 deletions
+5 -3
View File
@@ -19,7 +19,7 @@ export type RouteLayoutParams = {
}; };
export type RouteParams = 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. * Get the decoded page path from the params.
*/ */
export function getPagePathFromParams(params: RouteParams) { export function getPagePathFromParams(params: RouteParams) {
const decoded = decodeURIComponent(params.pagePath); if (!params.pagePath || params.pagePath.length === 0) {
return decoded; return '';
}
return params.pagePath.map((part) => decodeURIComponent(part)).join('/');
} }
function getSiteURLFromParams(params: RouteLayoutParams) { function getSiteURLFromParams(params: RouteLayoutParams) {
+4 -6
View File
@@ -589,12 +589,10 @@ function encodePathInSiteContent(rawPathname: string): {
return { pathname, routeType: 'static' }; return { pathname, routeType: 'static' };
} }
// If the pathname is an embedded page // If the pathname is an embedded page, let the optional catch-all route [[...pagePath]] handle it
const embedPage = pathname.match(/^~gitbook\/embed\/page\/(\S+)$/); // This naturally supports both empty paths (~gitbook/embed/page) and paths with segments
if (embedPage) { if (pathname.match(/^~gitbook\/embed\/page(\/.*)?$/)) {
return { return { pathname };
pathname: `~gitbook/embed/page/${encodeURIComponent(embedPage[1]!)}`,
};
} }
switch (pathname) { switch (pathname) {