From 1889c804721b8411bf5369469434b8367a1a9b96 Mon Sep 17 00:00:00 2001 From: Jacob Page Date: Mon, 13 Aug 2018 14:17:39 -0700 Subject: [PATCH] Update routing samples (#4864) Updated router samples to use the EventEmitter --- examples/with-google-analytics/components/Page.js | 4 +--- examples/with-loading/pages/_app.js | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/with-google-analytics/components/Page.js b/examples/with-google-analytics/components/Page.js index 421c5f2b..3677fa4e 100644 --- a/examples/with-google-analytics/components/Page.js +++ b/examples/with-google-analytics/components/Page.js @@ -4,9 +4,7 @@ import Header from './Header' import * as gtag from '../lib/gtag' -Router.onRouteChangeComplete = url => { - gtag.pageview(url) -} +Router.events.on('routeChangeComplete', url => gtag.pageview(url)) export default ({ children }) => (
diff --git a/examples/with-loading/pages/_app.js b/examples/with-loading/pages/_app.js index f6739c1b..0071bbb3 100644 --- a/examples/with-loading/pages/_app.js +++ b/examples/with-loading/pages/_app.js @@ -8,12 +8,12 @@ const linkStyle = { margin: '0 10px 0 0' } -Router.onRouteChangeStart = (url) => { +Router.events.on('routeChangeStart', (url) => { console.log(`Loading: ${url}`) NProgress.start() -} -Router.onRouteChangeComplete = () => NProgress.done() -Router.onRouteChangeError = () => NProgress.done() +}) +Router.events.on('routeChangeComplete', () => NProgress.done()) +Router.events.on('routeChangeError', () => NProgress.done()) export default class MyApp extends App { static async getInitialProps ({ Component, router, ctx }) {