Greums commited on
Commit
7cfb454
·
1 Parent(s): ca93406

dont use parent location

Browse files
Files changed (2) hide show
  1. README.md +0 -5
  2. src/app.tsx +6 -7
README.md CHANGED
@@ -5,11 +5,6 @@ colorFrom: blue
5
  colorTo: blue
6
  sdk: static
7
  app_file: ./dist/index.html
8
- header: mini
9
- custom_headers:
10
- cross-origin-embedder-policy: unsafe-none
11
- cross-origin-opener-policy: same-origin
12
- cross-origin-resource-policy: cross-origin
13
  pinned: false
14
  license: mit
15
  ---
 
5
  colorTo: blue
6
  sdk: static
7
  app_file: ./dist/index.html
 
 
 
 
 
8
  pinned: false
9
  license: mit
10
  ---
src/app.tsx CHANGED
@@ -64,8 +64,7 @@ export function App(): JSX.Element {
64
  }
65
 
66
  const updateRoute = useCallback(() => {
67
- // To make this script work in iframes we have to use `window.top`
68
- const url = new URL(window.top.location.href);
69
  const route = url.searchParams.get("route");
70
  if (route && route in routes) {
71
  _setRoute(route as keyof typeof routes);
@@ -91,17 +90,17 @@ export function App(): JSX.Element {
91
  updateRoute()
92
  }
93
 
94
- window.top.addEventListener('popstate', listener);
95
 
96
  return () => {
97
- window.top.removeEventListener('popstate', listener)
98
  }
99
  }, []);
100
 
101
 
102
  // Update URL params on route change
103
  const setRoute: RouteSetter = useCallback((route: Route, page?: number, id?: string) => {
104
- const url = new URL(window.top.location.href);
105
  url.searchParams.set("route", route);
106
  _setRoute(route);
107
 
@@ -124,8 +123,8 @@ export function App(): JSX.Element {
124
  const newUrl = url.toString();
125
 
126
  // Avoid to push the same URL mutiple time
127
- if (newUrl !== window.top.location.href) {
128
- window.top.history.pushState({}, "", newUrl);
129
  }
130
  }, []);
131
 
 
64
  }
65
 
66
  const updateRoute = useCallback(() => {
67
+ const url = new URL(window.location.href);
 
68
  const route = url.searchParams.get("route");
69
  if (route && route in routes) {
70
  _setRoute(route as keyof typeof routes);
 
90
  updateRoute()
91
  }
92
 
93
+ window.addEventListener('popstate', listener);
94
 
95
  return () => {
96
+ window.removeEventListener('popstate', listener)
97
  }
98
  }, []);
99
 
100
 
101
  // Update URL params on route change
102
  const setRoute: RouteSetter = useCallback((route: Route, page?: number, id?: string) => {
103
+ const url = new URL(window.location.href);
104
  url.searchParams.set("route", route);
105
  _setRoute(route);
106
 
 
123
  const newUrl = url.toString();
124
 
125
  // Avoid to push the same URL mutiple time
126
+ if (newUrl !== window.location.href) {
127
+ window.history.pushState({}, "", newUrl);
128
  }
129
  }, []);
130