Whenever a user accesses the path /
, I need it to redirect to the basePath
that has been previously set.
Below is my configuration in next.config.js
:
module.exports = {
basePath: '/docs',
}
This means that whenever the path /
is visited, it should be redirected to /docs
.
I have attempted the following approach:
module.exports = {
basePath: '/docs',
async rewrites() {
return [
{
source: '/',
destination: '/docs',
},
];
},
async redirects() {
return [
{
source: '/',
destination: '/docs',
},
];
},
};
The issue with these rewrites
and redirects
is that they only work with the basePath
.
For instance,
async redirects() {
return [
{
source: '/test',
destination: '/hello',
},
];
},
If I access /docs/test
, it will redirect to /docs/hello
. However, my intention is for /
to lead to /docs
.