未验证 提交 1c7cc60b 编写于 作者: S Shu Uesugi 提交者: GitHub

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.
上级 f7435b41
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 <Component {...pageProps} />
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册