使用PathUrlStrategy在Azure静态Web应用中的Flutter

huangapple go评论73阅读模式
英文:

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?

&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
&lt;/IfModule&gt;

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:

{
  &quot;navigationFallback&quot;: {
    &quot;rewrite&quot;: &quot;/index.html&quot;
  }
}

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

huangapple
  • 本文由 发表于 2023年4月13日 16:47:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定