next-routes
next-routes copied to clipboard
Add router event handlers
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
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
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'
Yes that's a typo I guess, it should Import it from your routes file
+1 on this!
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.
Same, +1 !