'Firebase keeps redirecting example.com/username to example.com/#/

I am trying to extract the username from the current URL example.com/username but firebase keeps directing it to example.com/#/ due to which username changes dynamically.

The website is built on flutter

firebase.json file:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "build/web",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "/**",
        "dynamicLinks": true,
        "destination": "/index.html"
      }
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

Visuals:

Visuals of redirection



Solution 1:[1]

If we look at the rewrites node in your firebase.json:

"rewrites": [
  {
    "source": "/**",
    "dynamicLinks": true,
    "destination": "/index.html"
  }
]

This tells Firebase Hosting to rewrite any incoming path ("source": "/**") to the same index.html file ("destination": "/index.html").

If you don't want it to perform this rewrite, you should remove it from the firebase.json configuration file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen