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

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

    If you are using Express or some other framework in the backend , you can add the similar configuration as below and check out the Webpack public path in the configuration, it should work fine even on reload if you are using BrowserRouter

    expressApp.get('/*', (request, response) => {
        response.sendFile(path.join(__dirname, '../public/index.html'));
    });
    

提交回复
热议问题