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
.
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
.
1 Answer
Reset to default 17You 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,
permanent: false
}
]
}
};
This will correctly redirect /
path to /docs
.
The same applies to rewrites
, if you were to use that instead.
routers
to redirect to the desired path when a user reaches/
(default index) path. – Prajwal Kulkarni Commented Oct 19, 2021 at 8:03