Skip to content

Commit

Permalink
OnRouteChange fix (#131)
Browse files Browse the repository at this point in the history
* resolve #126

* "react-hooks/exhaustive-deps": "off"
  • Loading branch information
kylehotchkiss authored Jul 26, 2021
1 parent 712e7cc commit 9b36644
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions website/src/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { META } from 'lib/constants';
import * as gtag from 'lib/gtag';
import { DefaultSeo } from 'next-seo';
import Router from 'next/router';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import 'styles/global.scss';

Expand All @@ -19,17 +19,19 @@ export function reportWebVitals({ id, name, label, value }) {
}

export default function App({ Component, pageProps }) {
const router = useRouter();

useEffect(() => {
// Google analytics:
// https://github.com/vercel/next.js/blob/canary/examples/with-google-analytics/pages/_app.js
const handleRouteChange = (url) => {
gtag.pageview(url);
};

Router.events.on('routeChangeComplete', handleRouteChange);
router.events.on('routeChangeComplete', handleRouteChange);

return () => {
Router.events.off('routeChangeComplete', handleRouteChange);
router.events.off('routeChangeComplete', handleRouteChange);
};
}, []);

Expand Down

1 comment on commit 9b36644

@vercel
Copy link

@vercel vercel bot commented on 9b36644 Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.