How to rewrite "/" to "/test"?
Answered
Shar Pei posted this in #help-forum
Shar PeiOP
Hello everyone, why can't the following code successfully rewrite "/" to "/test"?
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
return [
{
source: "/",
destination: "/test",
},
];
},
};
export default nextConfig;
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
return [
{
source: "/",
destination: "/test",
},
];
},
};
export default nextConfig;
26 Replies
What is not working about it?
Rewrites redirect but dont display in the url, so itll appear as though your still on '/' is that the behavior your wanting?
Shar PeiOP
When I visit http://localhost:3000 or http://localhost:3000/, the page content is not the content of /test
Let me test real quick
Shar PeiOP
It is acceptable whether the URL changes or not, but I don’t understand why the page content does not change.
Mines working flawlessly immediately.
Shar PeiOP
The code in this discussion (https://github.com/vercel/next.js/discussions/61808) can be successfully jumped.
Yeah its working as expected for me
Ohhhhh, delete your page.js in the base dir.
Answer
Apparently you cant rewrite if the page.js exsists it seems.
The second its there, it fails.
With page.js under app
without page.js under app
@Shar Pei
Shar PeiOP
Oh, that should be the problem you are talking about. I will try it.
Shar PeiOP
After deleting app/page.tsx, it works fine. Why is this?
Idk
lol
I dont work here, I just am trying to help.
/** @type {import('next').NextConfig} */
const nextConfig = {
async redirects() {
return [
{
source: '/',
destination: '/dashboard',
permanent: false,
},
]
},
};
export default nextConfig;This works without deleting the file tho
Shar PeiOP
Thanks a lot for your help!
Original message was deleted
No problem 🙂 Please mark the answer