gpt4 book ai didi

reactjs - 我可以将 NextJS 放在 localhost/next 等子文件夹中吗?

转载 作者:行者123 更新时间:2023-12-03 13:54:09 25 4
gpt4 key购买 nike

我尝试从 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 404 not found.

但真实文件包含在 .../page/about/index.js 中,而不是 /page/nextweb/about/index.js

我该怎么办?

最佳答案

To deploy a Next.js application under a sub-path of a domain you can use the basePath config option.
basePath allows you to set a path prefix for the application. For example, to use /docs instead of / (the default), open next.config.js and add the basePath config:

module.exports = {
basePath: '/docs',
}

来源:Base Path

关于reactjs - 我可以将 NextJS 放在 localhost/next 等子文件夹中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46475334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com