mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user