【问题标题】:Routes are not working after publishing my React Web App to Apache production server将我的 React Web App 发布到 Apache 生产服务器后,路由不起作用
【发布时间】:2020-07-09 23:34:15
【问题描述】:

我正在执行这个命令:

$ npm run-script build

初始页面运行良好,但任何带有路由的链接(例如“登录”)都不起作用。

如何更改脚本“构建”或更正?

有什么想法吗?

【问题讨论】:

  • 试试npm run build
  • 谢谢...在 Ubuntu 中运行脚本比运行脚本更好,但不能解决问题。 :(

标签: reactjs apache web routes production


【解决方案1】:

这可能不是您的构建问题。

我猜你正在使用 React 路由器 BrowserRouter?如果是这样,您的 React 应用程序正在处理路由。这意味着您的 Apache 配置必须配置为始终使用您的构建 index.html 响应请求的任何 url。

查看此示例配置:https://gist.github.com/alexsasharegan/173878f9d67055bfef63449fa7136042

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2017-05-31
    • 2020-01-18
    相关资源
    最近更新 更多