From 1c7cc60b8adc2119e0780afc53c367ff2eaaea73 Mon Sep 17 00:00:00 2001 From: Shu Uesugi Date: Fri, 4 Sep 2020 09:22:59 -0700 Subject: [PATCH] Use useRouter over Router for with-google-analytics example (#16846) Updating `with-google-analytics` example to be in line with [our documentation recommending `useRouter`](https://nextjs.org/docs/api-reference/next/router#userouter). Verified that it works. --- examples/with-google-analytics/pages/_app.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/with-google-analytics/pages/_app.js b/examples/with-google-analytics/pages/_app.js index f7bc525117e1b..79ebc4915b087 100644 --- a/examples/with-google-analytics/pages/_app.js +++ b/examples/with-google-analytics/pages/_app.js @@ -1,17 +1,18 @@ import { useEffect } from 'react' -import Router from 'next/router' +import { useRouter } from 'next/router' import * as gtag from '../lib/gtag' const App = ({ Component, pageProps }) => { + const router = useRouter() useEffect(() => { 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) } - }, []) + }, [router.events]) return }