Flutter web: Opening direct URL navigation working on local but not after deployment

1k views Asked by At

Even though there exists one Question that is already opened I didnt understand the approaches, but first to the problem itself.

On my local machine my routing works fine.

But when I host it I have the problem that I can navigate to a domain: http://www.example.com but not to a domain http://www.example.com/privacy-policy by direct URL Navigation.

The approaches that were suggested looked like:

  1. htaccess file: So basicly this approach suggested adding these lines to my htaccess:
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME}% !-d 
RewriteCond %{REQUEST_FILENAME}% !-f 
RewriteRule . /index.html [L]

I did and my whole file then looked like this as well. But it didnt change a thing. So did I something wrong? Should I implement the htaccess somehow?

  1. Adding to Firebase.json: The other suggestion was adding following code to my firebase.json file:
"hosting": {
  "rewrites": [ {
    "source": "**",
    "destination": "/index.html"
   } ]
}

My problem is that I dont have a firebase.json file, so what shall I do with this snippet? Is it only relevant when you use firebase hosting?

So I saw the both approaches but I didnt understand how to implement them. I get that the essential problem is trying to push the route on the same index.html file, but Im not understanding how to properly tackle the behaviour. Maybe I dont have the background knowledge to implement the solutions properly

1

There are 1 answers

1
Rajesh On

This issue is caused by flutter sdk only. Not caused by firebase or any other hosting services. I have tried all the redirection setups in firebase.json file, but later found the issue on github.

Upgrade to Flutter stable 3.7.4 or higher solved the issue.

Read the change notes https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel#374-feb-21-2023

See the issue on github

Hope this helps someone.