React-router urls don't work when refreshing or writing manually

前端 未结 30 2633
时光取名叫无心
时光取名叫无心 2020-11-21 05:07

I\'m using React-router and it works fine while I\'m clicking on link buttons, but when I refresh my webpage it does not load what I want.

For instance, I am in

30条回答
  •  有刺的猬
    2020-11-21 05:39

    If you're using firebase all you have to do is make sure you've got a rewrites property in your firebase.json file in the root of your app (in the hosting section).

    For example:

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

    Hope this saves somebody else a hoard of frustration and wasted time.

    Happy coding...

    Further reading on the subject:

    https://firebase.google.com/docs/hosting/full-config#rewrites

    Firebase CLI: "Configure as a single-page app (rewrite all urls to /index.html)"

提交回复
热议问题