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

前端 未结 30 2653
时光取名叫无心
时光取名叫无心 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:37

    If you are using Create React App:

    There's a great walk though of this issue with solutions for many major hosting platforms that you can find HERE on the Create React App page. For example, I use React Router v4 and Netlify for my frontend code. All it took was adding 1 file to my public folder ("_redirects") and one line of code in that file:

    /*  /index.html  200
    

    Now my website properly renders paths like mysite.com/pricing when entered into the browser or when someone hits refresh.

提交回复
热议问题