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

编程入门 行业动态 更新时间:2024-10-27 16:23:52
本文介绍了我可以将 NextJS 放在 localhost/next 等子文件夹中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试从 Next.js 构建静态文件,但我想将它放在共享主机的子文件夹或我的本地主机(如 localhost/nextweb)中.

I try to build static files from Next.js, but I want to put it in subfolder of shared host or my localhost like localhost/nextweb.

我试图找到一些例子,但我发现只将 NextJS 放在 root 中.

I tried to find some example, but I found only putting NextJS in root.

我的 next.config.js 看起来像

My next.config.js looks like

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: 'localhost/nextweb/' }

当我打开某个页面时,它正在工作,但是当我单击一个链接时,它会显示一个网络请求错误:

When I open some page, it's working, but when I click a link it shows me an network request error:

localhost/nextweb/_next/a5126d9c-d338-4eee-86ff-f4e6e7dbafa6/page/nextweb/about/index.js 404 未找到.

但真正的文件包含在 .../page/about/index.js 而不是 /page/nextweb/about/index.js

but real file is contain in .../page/about/index.js not /page/nextweb/about/index.js

我该怎么办?

推荐答案

要在域的子路径下部署 Next.js 应用程序,您可以使用 basePath 配置选项.basePath 允许您设置路径应用程序的前缀.例如,要使用 /docs 而不是 /(默认),打开 next.config.js 并添加 basePath 配置:

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', }

来源:基本路径

更多推荐

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

本文发布于:2023-11-14 16:45:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   文件   夹中   NextJS   localhost

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!