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

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

    For those who are using IIS 10, this is what you should do to make this right. Be sure that you are using browserHistory with this. As for reference I will give the code for the routing, but this is not what matters, what matters is the next step after the component code below:

    class App extends Component {
        render() {
            return (
                
                    
    ) } } render (, window.document.getElementById("app"));

    Since the problem is IIS receives request from client browsers, it will interpret the URL as if it is asking for a page, then returns a 404 page since there is no available page. Do the following:

    1. Open IIS
    2. Expand Server then open the Sites Folder
    3. Click the website/application
    4. Go to the Error Pages
    5. Open the 404 error status item in the list
    6. Instead of the option "Insert content from static file into the error response", change it to "Execute a URL on this site" and add "/" slash value to the URL.

    And it will now work fine.

    I hope it helps. :-)

提交回复
热议问题