React 使用browserHistory項(xiàng)目訪問(wèn)404問(wèn)題解決
最近項(xiàng)目里面用到了React但是發(fā)布到iis站點(diǎn)之后,路由地址 刷新訪問(wèn)直接404錯(cuò)誤。查閱資料之后發(fā)現(xiàn)是iis缺少配置URL重寫(xiě) 的問(wèn)題導(dǎo)致的。下面我們來(lái)圖形化配置,簡(jiǎn)單的配置下IIS
打開(kāi)IIS使用 Web平臺(tái)安裝程序
搜索 url
關(guān)鍵字,您會(huì)看到
直接安裝
關(guān)掉IIS 重新打開(kāi)IIS在站點(diǎn)右邊的控制面板可以看到一個(gè)URL重寫(xiě)的功能
新增配置如下
也可以直接 使用我的配置
配置如下 關(guān)鍵節(jié)點(diǎn)是: rewrite
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="ReactRouter" patternSyntax="ECMAScript" stopProcessing="true"> <match url=".*" /> <conditions> <add input="{HTTP_METHOD}" pattern="^GET$" /> <add input="{HTTP_ACCEPT}" pattern="^text/html" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> </conditions> <action type="Rewrite" url="/index.html" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
附:其他http-server配置說(shuō)明 Nginx
server { server_name react.yahui.wang listen 80; root /wwwroot/ReactDemo/dist; index index.html; location / { try_files $uri /index.html; } }
Tomcat
找到conf目錄下的web.xml文件,然后加上一句話(huà)讓他定位回來(lái)
<error-page> <error-code>404</error-code> <location>/index.html</location> </error-page>
Apache
.htaccess
文件配置如下
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule . /index.html [L] </IfModule>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)組件附帶吸頂效果的示例代碼
這篇文章主要為大家詳細(xì)介紹了React如何實(shí)現(xiàn)移動(dòng)端錨點(diǎn)跳轉(zhuǎn)組件附帶吸頂效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-01-01Ant?Design?組件庫(kù)之步驟條實(shí)現(xiàn)
這篇文章主要為大家介紹了Ant?Design組件庫(kù)之步驟條實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08react-redux集中式狀態(tài)管理及基本使用與優(yōu)化
react-redux把組件分為兩類(lèi),一類(lèi)叫做UI組件,一類(lèi)叫做容器組件,這篇文章主要介紹了集中式狀態(tài)管理<react-redux>基本使用與優(yōu)化,需要的朋友可以參考下2022-08-08react中ref獲取dom或者組件的實(shí)現(xiàn)方法
這篇文章主要介紹了react中ref獲取dom或者組件的實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05React如何使用refresh_token實(shí)現(xiàn)無(wú)感刷新頁(yè)面
本文主要介紹了React如何使用refresh_token實(shí)現(xiàn)無(wú)感刷新頁(yè)面,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04關(guān)于React動(dòng)態(tài)修改元素樣式的三種方式
這篇文章主要介紹了關(guān)于React動(dòng)態(tài)修改元素樣式的三種方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08