部署后未在根目录中找到静态文件(nextjs)



我将nextjs web部署在非根目录中,如'/next'not'/';之后在public floder中找不到静态文件。因为请求的url不是http://example.com/next/a.png但是http://example.com/a.png

我如何配置它以使其请求http://example.com/next/a.png'请帮我

您可以使用assetPrefix功能来指定您的附加目录。

// next.config.js
module.exports = {
// Use the CDN in production and localhost for development.
assetPrefix: process.env.NODE_ENV === 'production' ? '/next/' : '',
}

最新更新