reactjs - React app route not working after deployed to IIS
问题描述
I'm new to reactjs and currently facing some issue on IIS deployment for react app.
i execute npm run build and it generate a build folder, i then copy this folder to my IIS. When i browse the page, im able to view blank page but when i navigate to test route it shows 404.
I've try to add "homepage":"/" or "homepage":"." in my package.json but still the same.
index.html
This is my build structure
Any help is appreciated.
解决方案
每当您将反应页面部署到生产环境时,您都会面临这个问题。请参考此页面:https ://inthetechpit.com/2019/06/13/handle-client-side-routes-with-iis-on-page-refresh-react-app/
该问题发生在服务器中(不仅仅是 IIS,而是所有服务器)。您将需要安装扩展,然后将配置文件添加到前端构建目录的路径中。
要安装的扩展在这里:https ://www.iis.net/downloads/microsoft/url-rewrite
应该放在前端构建目录中的 web.config 文件的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
推荐阅读
- php - 也许是一个简单的数组问题
- javascript - 使用数学根据 URL 参数将数字相加?
- c++ - Linux Mint 19 下的 wxWidgets 源代码(.cpp 文件)在哪里提取以进行步入调试?
- typescript - 从数据对象到简化接口的打字稿
- java - 在 Heroku 上使用 Java 的 NodeJs 应用程序
- python - wxPython 应用程序在启动时显示空白屏幕
- php - htaccess 和 php 目录错误
- javascript - 轮播问题 | 角 6
- java - Spring Boot 自动生成 MySQL 数据库
- python - 尝试从 docker 容器 (Mac) 内部通过 SSH 隧道连接到 MongoDB