-
Notifications
You must be signed in to change notification settings - Fork 2
/
_app.tsx
executable file
·49 lines (40 loc) · 1.27 KB
/
_app.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import "../styles/globals.css";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import styled from "styled-components";
function MyApp({ Component, pageProps }) {
const router = useRouter();
const [pageLoading, setPageLoading] = useState(false);
useEffect(() => {
const handleStart = (url) => url !== router.asPath && setPageLoading(true);
const handleComplete = () => setPageLoading(false);
router.events.on("routeChangeStart", handleStart);
router.events.on("routeChangeComplete", handleComplete);
router.events.on("routeChangeError", handleComplete);
return () => {
router.events.off("routeChangeStart", handleStart);
router.events.off("routeChangeComplete", handleComplete);
router.events.off("routeChangeError", handleComplete);
};
});
// TODO 正式なローディングコンポーネントにする
const loadingComponent = <h2>Loading...</h2>;
return (
<div>
{pageLoading && <Loading></Loading>}
<Component {...pageProps} />
</div>
);
// return <Component {...pageProps} />;
// }
}
const Loading = styled.div`
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #ffee4a;
z-index: 2147483647;
`;
export default MyApp;