fridays / next-routes

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

Migration steps for nextjs inbuilt routing #350

Open santosh-cuemath opened 1 year ago

santosh-cuemath commented 1 year ago

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

asjadanis commented 1 year ago

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.