Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

refactor: fallback missing pages to home page (#4600)

Bogdan Chadkinc768f11f991e
diff --git a/apps/builder/app/shared/pages/use-switch-page.ts b/apps/builder/app/shared/pages/use-switch-page.ts
index 87cda128c7..b1bf3c6b50 100644
--- a/apps/builder/app/shared/pages/use-switch-page.ts
+++ b/apps/builder/app/shared/pages/use-switch-page.ts
@@ -12,6 +12,7 @@ import {
} from "~/shared/nano-states";
import { builderPath } from "~/shared/router-utils";
import { $selectedPage, selectPage } from "../awareness";
+import { findPageByIdOrPath } from "@webstudio-is/sdk";
const setPageStateFromUrl = () => {
const searchParams = new URLSearchParams(window.location.search);
@@ -19,7 +20,6 @@ const setPageStateFromUrl = () => {
if (pages === undefined) {
return;
}
- const pageId = searchParams.get("pageId") ?? pages.homePage.id;
let mode = searchParams.get("mode");
@@ -30,6 +30,12 @@ const setPageStateFromUrl = () => {
setBuilderMode(mode);
+ // check the page actually exists
+ // to avoid confusing the user with broken state
+ const pageId =
+ findPageByIdOrPath(searchParams.get("pageId") ?? "", pages)?.id ??
+ pages.homePage.id;
+
$selectedPageHash.set(searchParams.get("pageHash") ?? "");
selectPage(pageId);
};