【问题标题】:Next static html create wrong path for assets on nested pages下一个静态 html 为嵌套页面上的资产创建错误路径
【发布时间】:2021-04-22 19:19:14
【问题描述】:

我的 Nextjs 应用中有两种类型的页面:

 - index.html 
 -- admin/user.html
 -- admin/dashoard.html

在 next.config.js 我有

assetPrefix: "./",

当我运行 next build & next export 时,我会得到静态 html,其中包含指向资产的 URL,例如

<link rel="preload" href="./_next/static/css/47a9f0c415417b6241a6.css" as="style"/><link>

当我打开页面 index.html 时它运行良好(html 中的路径是 out/_next/static/...),但是当我打开 admin/user.html 时出现 404 错误,因为它试图从 out/admin/_next/static/... 获取资产

Nextjs 或者 Nginx 怎么解决?

【问题讨论】:

  • 试试:assetPrefix: "/",
  • @RichardSmith 它会从文件系统的核心创建路径,而不是我想要的文件结构深处的项目
  • 如果您的应用程序托管在子路径中,您不应该将basePathassetPrefix 设置为子路径吗?

标签: reactjs nginx next.js


【解决方案1】:

好的。我使用 nginx 处理它,在 next.config assetPrefix:''

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2022-10-01
    • 1970-01-01
    相关资源
    最近更新 更多