我现在正在尝试将我的 /archives 重写为 archives.localhost 。我试图理解重写,我想我对它有了基本的了解。当我转到主索引页面 archives.localhost:3000/ 时,页面加载完美,但由于某种原因,当我尝试加载 archives.localhost:3000/test 时,我收到 404 错误,即使该页面存在。我做错了什么?
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
missingSuspenseWithCSRBailout: false,
},
async rewrites() {
return {
beforeFiles: [
// rewrite projects to the propper path
{
source: `/:path((?!api|auth|_next).)*`,
has: [
{
type: 'host',
value: 'archives.localhost/:path*',
},
],
destination: '/archives/:path*',
},
{
// fallback
source: '/:path*',
destination: '/:path*',
}
]
}
}
}
export default nextConfig;
您能否尝试通过替换代码中的
rewrite rule
来更正 async rewrites()
。
async rewrites() {
return {
afterFiles: [
// Here we are rewriting requests to archives.localhost:3000 to archives.localhost
{
source: '/archives/:path*',
destination: 'http://archives.localhost/:path*',
},
// This is a Fallback for other requests.
{
source: '/:path*',
destination: '/:path*',
},
],
};
}
如果这有帮助,请告诉我。