forked from aeharding/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouter.tsx
29 lines (25 loc) · 891 Bytes
/
Router.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { IonReactMemoryRouter, IonReactRouter } from "@ionic/react-router";
import { createMemoryHistory } from "history";
import React, { useEffect } from "react";
import { isAppleDeviceInstalledToHomescreen } from "./helpers/device";
export default function Router({ children }: { children: React.ReactNode }) {
const history = createMemoryHistory();
useEffect(() => {
const unListen = history.listen(() => {
window.scrollTo(0, 0);
});
return () => {
unListen();
};
}, [history]);
/**
* This is a total hack to prevent native page swipe gesture
* on iOS. If there's no page history to swipe,
* what are you going to do, Apple... 😈
*/
if (isAppleDeviceInstalledToHomescreen())
return (
<IonReactMemoryRouter history={history}>{children}</IonReactMemoryRouter>
);
return <IonReactRouter>{children}</IonReactRouter>;
}