我尝试从 Next.js 构建静态文件,但我想将其放在共享主机或本地主机的子文件夹中,例如 localhost/nextweb。
我试图找到一些例子,但我发现只将 NextJS 放在根目录中。
我的 next.config.js 看起来像
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { ANALYZE } = process.env
module.exports = {
webpack: function (config) {
if (ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: 8888,
openAnalyzer: true
}))
}
return config
},
exportPathMap: () => ({
"/": { page: "/" },
"/about": { page: "/about" }
}),
assetPrefix: 'http://localhost/nextweb/'
}
当我打开某个页面时,它正在工作,但是当我单击链接时,它会显示网络请求错误:
http://localhost/nextweb/_next/a5126d9c-d338-4eee-86ff-f4e6e7dbafa6/page/nextweb/about/index.js http://localhost/nextweb/_next/a5126d9c-d338-4eee-86ff-f4e6e7dbafa6/page/nextweb/about/index.js404 未找到。
但真实文件包含在.../page/about/index.js not /page/nextweb/about/index.js
我该怎么办?
要在域的子路径下部署 Next.js 应用程序,您可以使用basePath
配置选项。
basePath
允许您设置应用程序的路径前缀。例如,要使用/docs
代替/
(默认),打开next.config.js
并添加 basePath 配置:
module.exports = {
basePath: '/docs',
}
Source: 基本路径 https://nextjs.org/docs/api-reference/next.config.js/basepath
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)