我有以下地址/blog/post-1、/blog/post-2和我想重写到/post-1、/post-2的所有路径。我在文件next.config.js中配置如下
async rewrites() {
return [
{
source: '/:slug',
destination: '/blog/:slug',
},
]
}然而,旧的道路和新的道路都有效吗?我该怎么办?
发布于 2022-08-01 14:47:37
如果您试图将它们从/blog/post-1重定向到/post-1/,并且需要路径参数,您就会错误地设置它们。
从docs https://nextjs.org/docs/api-reference/next.config.js/rewrites
module.exports = {
async rewrites() {
return [
{
source: '/blog/:path*',
destination: '/:path*', // The :path parameter is used here so will not be automatically passed in the query
},
]
},
}https://stackoverflow.com/questions/73195367
复制相似问题