Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
How to redirect / into basePath in Next.js config?

Every time that user enter into / I want to redirect into basePath that I already set.

Here is my next.config.js

module.exports = {
  basePath: '/docs',
}

So every time I enter path / I want to redirect into /docs.

Here is what I've tried.

module.exports = {
  basePath: '/docs',
  async rewrites() {
    return [
      {
        source: '/',
        destination: '/docs',
      },
    ];
  },
  async redirects() {
    return [
      {
        source: '/',
        destination: '/docs',
      },
    ];
  },
};

The problem is this rewrites and redirects are working with basePath only.

For example

async redirects() {
        return [
          {
            source: '/test',
            destination: '/hello',
          },
        ];
      },

I enter into /docs/test it will redirect into /docs/hello.

But I want / to go to /docs.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use basePath: false option to disable the automatic basePath prefixing of source and destination.

module.exports = {
    basePath: '/docs',
    async redirects() {
        return [
            {
                source: '/',
                destination: '/docs',
                basePath: false
            }
        ]
    }
};

This will correctly redirect / path to /docs.

The same applies to rewrites, if you were to use that instead.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!