英文:
Flutter - Using PathUrlStrategy on Azure Static Web App
问题
I have a flutter web app that runs fine locally, however, when uploaded to the Azure infrastructure (via Azure Static Web Apps) I run into problems using the PathUrlStrategy option - when the url is entered manually there's a 404 returned. From here it states that there's some server config to do (but isn't clear about what).
After a bit of digging, I've found a reference to a .htaccess file (problem seems to be similar - treating the path as a subdirectory) but I'm not sure how to apply it to the static web app config?
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
Thanks in advance,
英文:
I have a flutter web app that runs fine locally, however, when uploaded to the Azure infrastructure (via Azure Static Web Apps) I run into problems using the PathUrlStrategy option - when the url is entered manually there's a 404 returned.  From here it states that there's some server config to do (but isn't clear about what).
After a bit of digging, I've found a reference to a .htaccess file (problem seems to be similar - treating the path as a subdirectory) but I'm not sure how to apply it to the static web app config?
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
Thanks in advance,
答案1
得分: 0
使用此链接,具体是这部分:
{
  "navigationFallback": {
    "rewrite": "/index.html"
  }
}
我已将staticwebapp.config.json文件添加到Flutter应用的根目录。在pubspec.yaml中添加以下行似乎也没有被使用:
assets:
  - staticwebapp.config.json
英文:
Okay - got there in the end!
Using this, specifically this bit:
{
  "navigationFallback": {
    "rewrite": "/index.html"
  }
}
I've added a staticwebapp.config.json file to the root of the flutter app.  This didn't seem to be utilised until also adding this line to pubspec.yaml
  assets:
    - staticwebapp.config.json
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论