React Native for Web应用部署至Azure环境的目标目录咨询
问题解决:React Native for Web部署至Azure Web App后仍显示默认Python页面
你的文件上传目录wwwroot是正确的,问题出在Azure Web App的运行时配置和静态文件路由设置上,以下是解决步骤:
切换运行时堆栈
登录Azure门户,进入你的Web App,依次点击设置->配置->常规设置,将运行时堆栈修改为Static HTML(推荐,适合静态单页应用)或对应版本的Node.js,保存后重启Web App。添加静态路由配置文件
如果使用Windows主机,在wwwroot目录下创建web.config文件,内容如下:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="React Routes" stopProcessing="true"> <match url=".*" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="/index.html" /> </rule> </rules> </rewrite> </system.webServer> </configuration>如果是Linux主机,在
wwwroot目录下创建.htaccess文件,内容如下:RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L]确认文件结构
确保本地web-build文件夹内的所有文件(如index.html、static文件夹等)直接上传至wwwroot根目录,不要嵌套在wwwroot/web-build子目录中。
完成以上操作后,重启Web App,再次访问站点即可正常加载你的React Native for Web应用。
内容的提问来源于stack exchange,提问作者mightycode Newton
相关产品推荐
相关产品推荐

