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.

Fix url hash (#1838)

Ivan Starkov5bae55124c36
diff --git a/packages/sdk-components-react-remix/src/shared/remix-link.tsx b/packages/sdk-components-react-remix/src/shared/remix-link.tsx
index 32cdf1488a..0782b49f80 100644
--- a/packages/sdk-components-react-remix/src/shared/remix-link.tsx
+++ b/packages/sdk-components-react-remix/src/shared/remix-link.tsx
@@ -23,9 +23,14 @@ export const wrapLinkComponent = (BaseLink: typeof Link) => {
if (href?.type === "page") {
let to = href.page.path === "" ? "/" : href.page.path;
+ const urlTo = new URL(to, "https://any-valid.url");
+ to = urlTo.pathname;
+
if (href.hash !== undefined) {
- to += `#${href.hash}`;
+ urlTo.hash = href.hash;
+ to = `${urlTo.pathname}${urlTo.hash}`;
}
+
return <RemixLink {...props} to={to} ref={ref} />;
}
diff --git a/packages/sdk-components-react/src/link.tsx b/packages/sdk-components-react/src/link.tsx
index cb8b7def6d..95788bb895 100644
--- a/packages/sdk-components-react/src/link.tsx
+++ b/packages/sdk-components-react/src/link.tsx
@@ -19,12 +19,17 @@ export const Link = forwardRef<HTMLAnchorElement, Props>((props, ref) => {
let url = "#";
switch (href?.type) {
- case "page":
+ case "page": {
url = href.page.path === "" ? "/" : href.page.path;
+ const urlTo = new URL(url, "https://any-valid.url");
+ url = urlTo.pathname;
+
if (href.hash !== undefined) {
- url += `#${href.hash}`;
+ urlTo.hash = href.hash;
+ url = `${urlTo.pathname}${urlTo.hash}`;
}
break;
+ }
case "asset":
url = `${assetBaseUrl}${href.asset.name}`;
break;