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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
import { appendSystemSearch, type System } from "@webstudio-is/sdk";
export const getPreviewCurrentUrl = (
currentSystem: Pick<System, "pathname" | "search">,
hash: string
) => {
// Preview renders inside the builder canvas route, so window.location points
// at the builder shell, not the page being previewed. Recreate the page URL
// from the selected page system data so :local-link state matches preview
// navigation, including query params and hash-only links.
const currentUrl = new URL(currentSystem.pathname, "https://webstudio.local");
const searchParams = new URLSearchParams();
appendSystemSearch(searchParams, currentSystem.search);
currentUrl.search = searchParams.toString();
currentUrl.hash = hash;
return currentUrl;
};