fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Add router event handlers #198

Closed Msea closed 1 year ago

Msea commented 6 years ago

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

fridays commented 6 years ago

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

Msea commented 6 years ago

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'

fridays commented 6 years ago

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

mpint commented 6 years ago

+1 on this!

Msea commented 6 years ago

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.

stephane-r commented 6 years ago

Same, +1 !