next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

Migration steps for nextjs inbuilt routing

Open santosh-cuemath opened this issue 1 year ago • 1 comments

Are there any easy migration step to migrate to inbuilt nextjs routing

santosh-cuemath avatar Apr 22 '23 05:04 santosh-cuemath

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.

asjadanis avatar Aug 17 '23 23:08 asjadanis

Thank you so much for your answer, @asjadanis ! It worked for me with Next.js v9.5.5

pachopa avatar Jun 12 '24 22:06 pachopa