diff --git a/pages/_app.tsx b/pages/_app.tsx
index fb2b1e0..587e056 100644
--- a/pages/_app.tsx
+++ b/pages/_app.tsx
@@ -1,11 +1,11 @@
-import React, { useEffect } from "react";
-import { Container } from "next/app";
+import React from "react";
+import App, { Container } from "next/app";
import { Button, Text, Pane, Popover, Link, Heading } from "evergreen-ui";
import Navigator from "@components/Navigator";
import "@styles/main.css";
import NProgress from "nprogress";
-import { useRouter } from "next/router";
+import Router from "next/router";
import { activeRouteData } from "@utils/routes";
let reactGa;
@@ -57,117 +57,129 @@ function renderHeadWay() {
})("https://cdn.headwayapp.co/widget.js");
}
-export default function App({ Component, pageProps }) {
- const router = useRouter();
+export default class extends App {
+ timer: any;
- useEffect(() => {
- reactGa && reactGa.pageview(router.pathname);
+ private stopProgress = pathname => {
+ reactGa && reactGa.pageview(pathname);
+ clearTimeout(this.timer);
+ NProgress.done();
+ };
- const startProgress = () => NProgress.start();
+ private startProgress = () => NProgress.start();
- let timer;
- const stopProgress = pathname => {
- reactGa && reactGa.pageview(pathname);
- clearTimeout(timer);
- NProgress.done();
- };
+ private showProgressBar = () => {
+ this.timer = setTimeout(this.startProgress, 300);
+ Router.events.on("routeChangeComplete", this.stopProgress);
+ Router.events.on("routeChangeError", this.stopProgress);
+ };
- const showProgressBar = () => {
- timer = setTimeout(startProgress, 300);
- router.events.on("routeChangeComplete", stopProgress);
- router.events.on("routeChangeError", stopProgress);
- };
+ componentDidMount(): void {
+ reactGa && reactGa.pageview(Router.pathname);
+ Router.events.on("routeChangeStart", this.showProgressBar);
+ }
- router.events.on("routeChangeStart", showProgressBar);
+ componentWillUnmount(): void {
+ Router.events.off("routeChangeComplete", this.stopProgress);
+ Router.events.off("routeChangeError", this.stopProgress);
+ Router.events.off("routeChangeStart", this.showProgressBar);
+ this.timer && clearTimeout(this.timer);
+ }
- return () => {
- router.events.off("routeChangeComplete", stopProgress);
- router.events.off("routeChangeError", stopProgress);
- router.events.off("routeChangeStart", showProgressBar);
- timer && clearTimeout(timer);
- };
- }, []);
+ render(): JSX.Element {
+ const { Component, pageProps } = this.props;
- renderHeadWay();
+ renderHeadWay();
- const activeRoute = activeRouteData(router.pathname);
+ const activeRoute = IN_BROWSER
+ ? activeRouteData(Router.pathname)
+ : undefined;
- return (
-
-
- {activeRoute && (activeRoute.title || activeRoute.searchTerm)}
-
-
-
-
-
- {logo}
-
-
-
- (
-
-
- Your Data is always with you.
-
-
-
- This website is static which means no data goes to the server.
- Everything is done on the client side. The code of this
- website is open source which you can find{" "}
-
- on GitHub
-
-
-
- )}
+ return (
+
+
+ {activeRoute && (activeRoute.title || activeRoute.searchTerm)}
+
+
+
+
+
+ {logo}
+
+
+
+ (
+
+
+ Your Data is always with you.
+
+
+
+ This website is static which means no data goes to the
+ server. Everything is done on the client side. The code of
+ this website is open source which you can find{" "}
+
+ on GitHub
+
+
+
+ )}
+ >
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
- );
+
+
+
+
+
+ );
+ }
}