reactjsnext.js

Setting up the home page on Next.js


Does anybody know how to define any specific page in Next.js as the root (the home page)?

I have been looking online and was not able to find any concrete solutions. This is suppose to be a very common use case.

There is this other post, Using Next.js next-routes, how to define a home route for the base web page?, but it recommends creating a server for it.

Is there any "NextJs" way of setting up a Home Page?

Thanks in advance!


Solution

  • Here is the solution offered by nextjs.

    Create or edit the file next.config.js in the root directory:

    module.exports = {
      async redirects() {
        return [
          {
            source: '/',
            destination: '/about',
            permanent: true,
          },
        ]
      },
    }

    Source: https://nextjs.org/docs/api-reference/next.config.js/redirects