fridays / next-routes

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

new feature: options.routeFound #45

Closed Sly777 closed 7 years ago

Sly777 commented 7 years ago

Added option to handle process after route found

Example:

const routeHandler = routes.getRequestHandler(app, {
  routeFound: (req, res, url, queryParams) => {
    renderAndCache(req, res, url, queryParams);
  }
});

function renderAndCache() {
   // handle for caching
}
fridays commented 7 years ago

Thanks for contributing! Please see if https://github.com/fridays/next-routes/pull/51 works for you

Sly777 commented 7 years ago

I'm closing this PR because of #51 . Thanks @fridays!

fridays commented 7 years ago

Reopening because it is the right place for a request handler 🌴

Sly777 commented 7 years ago

Hey @fridays, I made changes as you said but the only difference is I chose a name as "customHandler" to avoid some wording confusion.

fridays commented 7 years ago

Thanks, looks good!

Sly777 commented 7 years ago

I updated the example @HaNdTriX

fridays commented 7 years ago

@Sly777 I think @HaNdTriX meant to only change renderAndCache to app.render in the example. Query transforms are not implemented here and redirects should better happen inside getInitialProps. If you could change this, we can merge 👍

Sly777 commented 7 years ago

oooh, I see :) Okay I updated as you want, @fridays.

fridays commented 7 years ago

Thanks! It's now there in version 1.0.29