Make chrome work-around work in iframes (#9200)

This commit is contained in:
Bram Kragten
2021-05-21 09:09:31 +02:00
committed by GitHub
parent 9328576b55
commit fd9bb4d8cc
10 changed files with 79 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import { fireEvent } from "./dom/fire_event";
import { mainWindow } from "./dom/get_main_window";
declare global {
// for fire event
@@ -12,24 +13,24 @@ declare global {
export const navigate = (_node: any, path: string, replace = false) => {
if (__DEMO__) {
if (replace) {
top.history.replaceState(
top.history.state?.root ? { root: true } : null,
mainWindow.history.replaceState(
mainWindow.history.state?.root ? { root: true } : null,
"",
`${top.location.pathname}#${path}`
`${mainWindow.location.pathname}#${path}`
);
} else {
top.location.hash = path;
mainWindow.location.hash = path;
}
} else if (replace) {
top.history.replaceState(
top.history.state?.root ? { root: true } : null,
mainWindow.history.replaceState(
mainWindow.history.state?.root ? { root: true } : null,
"",
path
);
} else {
top.history.pushState(null, "", path);
mainWindow.history.pushState(null, "", path);
}
fireEvent(top, "location-changed", {
fireEvent(mainWindow, "location-changed", {
replace,
});
};