A custom handler, as described in the README, can alter the way routes declared in routes.js work.
Is it possible to add a custom handler to all other routes (those handled "natively" by next.js), as described in next.js' readme?
can you give an example of something you'd like to do?
it sounds at first like you're asking about a way to intercept / modify the request before next renders it. if that's the case, the example in the readme shows how to do that. specifically:
const handler = routes.getRequestHandler(app, ({req, res, route, query}) => {
// do just about anything you want here
app.render(req, res, route.page, query)
})
What I mean is that given this file structure:
├── page1.js
└── page2.js
and such routes definition:
.add('page1')
page2 seems to be handled without next-routes 'involved', and the getRequestHandler callback does not catch requests for /page2.
So I was wondering if it's a bug and how can I have a custom handler for routes not declared in routes definition (routes.js).
my first guess would be that the default next router is preferring its own file system routing over next-routes
have you set useFileSystemPublicRoutes: false in next.config.js ? (see docs)
Using useFileSystemPublicRoutes: false necessitates declaring _all_ routes in the custom router, next-routes in this case, which brings us back to square one.
I was looking for a way to use both next-routes (for parametrised routes, such as /post/:id) and next router (for everything else).
It seems that currently accessing getRequestHandler for routes not declared in routes.js is impossible.
Most helpful comment
Using
useFileSystemPublicRoutes: falsenecessitates declaring _all_ routes in the custom router,next-routesin this case, which brings us back to square one.I was looking for a way to use both
next-routes(for parametrised routes, such as/post/:id) andnextrouter (for everything else).It seems that currently accessing
getRequestHandlerfor routes not declared inroutes.jsis impossible.