next-routes
next-routes copied to clipboard
Migration steps for nextjs inbuilt routing
Are there any easy migration step to migrate to inbuilt nextjs routing
You can use the next js rewrites in your next.config.json
for this.
// next.config.json
// Existing routes configured with next-routes
const routes = require("./your-next-routes")
// Map the routes to the below shape
// routes = [{ source: '/about', destination: '/' }]
module.exports = {
async rewrites() {
return [...routes]
}
}
In your server.js
file delete routes import and use app.getRequestHandler()
// server.js
const handle = app.getRequestHandler();
server.get("*", (req, res) => {
return handle(req, res);
});
Might have to delete the .next
folder before giving it a go.
Thank you so much for your answer, @asjadanis ! It worked for me with Next.js v9.5.5