浏览器刷新显示 "page not found" 错误,当 single-spa 应用程序部署在子目录中时

Browser refresh shows "page not found" error, when the single-spa application is deployed in the subdirectory

我的 single-spa 包含 4 个 React 应用程序。每个都有自己的 react-router-dom。如果我从 4 个应用程序之一点击浏览器刷新,它会显示找不到页面。应用程序部署在 Linux OS.

的 apache 服务器中

我不知道我是否缺少基本应用程序中的任何配置。它在 webpack 和 node 的开发服务器中工作正常。

是的,因为您部署的应用程序不知道路由。在单页应用程序中,只有 / 路由存在。 SPA 中的所有路由都是客户端路由,不会向服务器发出单独的 GET 请求。

我在将我的应用程序部署到 netlify 时遇到了同样的问题。它显示默认的 netlify 404 页面。然后我将 _redirects 文件添加到 public 目录,内容如下:

/* /index.html 200

这将所有 404 路由重定向到默认 index.html,因此使用了客户端路由。您需要为您的部署版本找到类似的东西。