question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Route Events handlers are not being called

See original GitHub issue

Following the instructions in README to listen to route events doesn’t work

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

It should be called and I should see the console logs

Current Behavior

Nothing

Steps to Reproduce (for bugs)

  1. Add the code (either in pages/*.js or pages/_document.js)
// onRouteChangeStart(url) - Fires when a route starts to change
Router.onRouteChangeStart = (url) => {
  console.log('App is changing to: ', url)
}

// onRouteChangeComplete(url) - Fires when a route changed completely
Router.onRouteChangeComplete = (url) => {
  console.log('App has changed to: ', url)
}

// onRouteChangeError(err, url) - Fires when there's an error when changing routes
Router.onRouteChangeError = (err, url) => {
  console.log('App has error when changing: ', err, url)
}

// onBeforeHistoryChange(url) - Fires just before changing the browser's history
Router.onBeforeHistoryChange = (url) => {
  console.log('App is changing to before history change: ', err, url)
}

// onAppUpdated(nextRoute) - Fires when switching pages and there's a new version of the app
Router.onAppUpdated = (nextRoute) => {
  console.log('App is updating to: ', nextRoute)
}
  1. Refresh the page, and click around and add some Router.push events
  2. Nothing in inspector
  3. ??

Context

I can’t use this to track pageviews for my in-house analytics system.

Your Environment

Tech Version
next 2.4.6
node 8.1.3
OS 10.12.5
browser chrome 60.0.3112.72 (Official Build) beta (64-bit)
etc

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

11reactions
Ponjimoncommented, Jan 19, 2018

I currently have the problem that onRouteChangeStart is called, but onRouteChangeComplete is not despite the fact that I visually see the changes e.g. it successfully changed the route…

What can I do?

0reactions
pencilcheckcommented, Jul 27, 2017

Thanks, will test again later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Route Events handlers are not being called #2644 - GitHub
I currently have the problem that onRouteChangeStart is called, but onRouteChangeComplete is not despite the fact that I visually see the ...
Read more >
Event handlers not being called with React and Electron
I'm trying out Electron and I've set up an app with typescript and react. My react components in the renderer aren't responding to...
Read more >
Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
Read more >
How-To: Route messages to different event handlers
Learn how to route messages from a topic to different event handlers based on CloudEvent fields.
Read more >
Events and routed events overview - UWP - Microsoft Learn
Registering handlers for already-handled routed events​​ Earlier we said that setting Handled to true prevents most handlers from being called.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found