unable to rewrite URL
Answered
Naeemgg posted this in #help-forum
NaeemggOP
I want to rewrite URL from
what I want is to show in the browser
/en/dashboard to /.const nextConfig = {
async rewrites(){
return[{
source:"/en", destination:"/dashboard",
}]}
}
module.exports = nextConfigwhat I want is to show in the browser
http://localhost:3000 but the contents should be of http://localhost:3000/en/dashboard25 Replies
@Naeemgg I want to rewrite URL from `/en/dashboard` to `/`.
jsx
const nextConfig = {
async rewrites(){
return[{
source:"/en", destination:"/dashboard",
}]}
}
module.exports = nextConfig
what I want is to show in the browser `http://localhost:3000` but the contents should be of `http://localhost:3000/en/dashboard`
try
const nextConfig = {
async rewrites() {
return [
{
source: "/",
destination: "/en/dashboard",
},
];
},
}
module.exports = nextConfig@Ray try
ts
const nextConfig = {
async rewrites() {
return [
{
source: "/",
destination: "/en/dashboard",
},
];
},
}
module.exports = nextConfig
NaeemggOP
async rewrites(){
return[
{
source:"/en",
destination:"/dashboard",
}
]
}
its working like this but I can see
/en/dashboard in the URLdo you have middleware which doing redirecting?
NaeemggOP
yes
@Ray try
ts
const nextConfig = {
async rewrites() {
return [
{
source: "/",
destination: "/en/dashboard",
},
];
},
}
module.exports = nextConfig
this should do what you said in the question
NaeemggOP
Yep
@Naeemgg Yep
try clear browser cache
@Naeemgg Ok let me disable i18n and try again
how did you disable i18n? rename
middleware.ts to _middleware.ts?Answer
NaeemggOP
middl.ts@Ray try clear browser cache
NaeemggOP
roger that
do you have
app/page.tsx?NaeemggOP
yes
import { redirect } from "next/navigation";
const page = () => {
// redirect("/dashboard")
return (
<div>
HELLO
</div>
)
}
export default pageNaeemggOP
ok
IT WORKED
now could you please tell me how to do this exact thing with middleware??
with i18n??
I'm using next-auth and i18n which are using middleware
@Naeemgg now could you please tell me how to do this exact thing with middleware??
does it work with middleware?
NaeemggOP
Now its working
had to handle the
NextResponse.redirect