Share via

How to fix problem with Static Web Apps and React Routing?

Miroslav Turek 0 Reputation points
2025-01-07T19:35:29.0733333+00:00

Hello guys.

I have problem with Static Web Apps and probably with staticwebapp.config.json.

I have domain www.mypage.com and everything works fine until you do not try to refresh page eg. with address https://mypage.com/details/8. I already added

"navigationFallback": {  "rewrite": "/index.html"} but still not wotking.

Do you have any idea what I could try yet? Thanks for any advise.

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.


1 answer

Sort by: Most helpful
  1. Anonymous
    2025-01-28T09:34:10.33+00:00

    Hi @Miroslav Turek ,

    Thank you for reaching out to Microsoft Q&A.

    Make sure the staticwebapp.config.json file is located in the root directory of your application, and try the below configuration:

    
    {
    
      "routes": [
    
        {
    
          "route": "/details/*",
    
          "serve": "/index.html",
    
          "statusCode":200
    
        }
    
      ],
    
      "navigationFallback": {
    
        "rewrite": "/index.html",
    
        "exclude":["/api/*]
    
      }
    
    }
    
    

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.