Can't get slug after a route rewrite
Unanswered
White-horned horntail posted this in #help-forum
White-horned horntailOP
In my next.config.js, I have the following route rewrite:
async rewrites() {
return [
{
source: '/my-route/:id*',
destination: '/my-route',
},
]
}
According to the documentation here: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites#rewrite-parameters, I believe I should be able to get the old :id slug as a query parameter, however I don't actually see the :id being added as a query param. Any help would be appreciated!
async rewrites() {
return [
{
source: '/my-route/:id*',
destination: '/my-route',
},
]
}
According to the documentation here: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites#rewrite-parameters, I believe I should be able to get the old :id slug as a query parameter, however I don't actually see the :id being added as a query param. Any help would be appreciated!
5 Replies
@White-horned horntail In my next.config.js, I have the following route rewrite:
async rewrites() {
return [
{
source: '/my-route/:id*',
destination: '/my-route',
},
]
}
According to the documentation here: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites#rewrite-parameters, I believe I should be able to get the old :id slug as a query parameter, however I don't actually see the :id being added as a query param. Any help would be appreciated!
you can only access this :id as a query parameter inside the
but when the request reaches your actual page, the id parameter is lost
destination string. so /my-route/something/:id works there.but when the request reaches your actual page, the id parameter is lost
White-horned horntailOP
@joulev ahh good to know :/ thanks!
does that conflict with the documentation though? it says
module.exports = {
async rewrites() {
return [
{
source: '/old-about/:path*',
destination: '/about', // The :path parameter isn't used here so will be automatically passed in the query
},
]
},
}
module.exports = {
async rewrites() {
return [
{
source: '/old-about/:path*',
destination: '/about', // The :path parameter isn't used here so will be automatically passed in the query
},
]
},
}
@White-horned horntail does that conflict with the documentation though? it says
module.exports = {
async rewrites() {
return [
{
source: '/old-about/:path*',
destination: '/about', // The :path parameter isn't used here so will be automatically passed in the query
},
]
},
}
Oh wow didn’t know about this. Hmm then it’s weird. Can you get it in useParams or useSearchParams (app router) or useRouter().query (pages router)?
White-horned horntailOP
@joulev nope, i've tried everything 🥲