next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

Add router event handlers

Open Msea opened this issue 7 years ago • 6 comments

nextjs supports handeling router events https://nextjs.org/docs#routing

onRouteChangeStart onRouteChangeComplete onRouteChangeError onBeforeHistoryChange

This branch adds those events to next-routes with the following syntax:

routes.onRouteChangeStart((url) => {
  console.log('App is changing to: ', url);
})

Related to these issues

  • https://github.com/fridays/next-routes/issues/112
  • https://github.com/fridays/next-routes/issues/189

Msea avatar Jun 25 '18 13:06 Msea

Thanks but Router events should work just like in next.js could you try again with the example code given in https://github.com/fridays/next-routes/issues/112#issuecomment-377714239

fridays avatar Jun 29 '18 18:06 fridays

In that example Router is being imported from "routes". I don't need to import the router that I exported from my routes file? import {Router} from './routes' rather than import {Router} from 'routes'

Msea avatar Jul 05 '18 15:07 Msea

Yes that's a typo I guess, it should Import it from your routes file

fridays avatar Jul 06 '18 06:07 fridays

+1 on this!

mpint avatar Aug 03 '18 23:08 mpint

Hmm. Not sure why it wasn't working for me then, since my code was similar to the sample. As it turns out I didn't end up using the route handlers for my use case anyway. And I'm sorry to say I haven't had a chance to play with this. I suppose you can just close the issue, if you say it's probably an error on my side of things.

Msea avatar Aug 20 '18 03:08 Msea

Same, +1 !

stephane-r avatar Nov 02 '18 08:11 stephane-r