Skip to content

Commit 36c400f

Browse files
authored
enhance to support iframe url with query (#3)
* enhance to support iframe url with search params
1 parent dcf92e0 commit 36c400f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/sync-host/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ export class HostSync extends Sync {
5353

5454
this.iframe = iframe;
5555

56-
this.iframe.src = url + this.getState();
56+
try {
57+
const {origin, pathname, search} = new URL(url);
58+
const updatedPathname = pathname === '/' ? '' : pathname;
59+
this.iframe.src = `${origin}${updatedPathname}${this.getState()}${search}`;
60+
} catch (error) {
61+
this.iframe.src = url + this.getState();
62+
console.error('Invalid URL of iframe', url);
63+
}
5764

5865
!this.iframe['iFrameResizer'] &&
5966
iFrameResize(

0 commit comments

Comments
 (0)