React nested route fails to load on refresh

后端 未结 3 1003
清酒与你
清酒与你 2021-02-03 10:44

I have a React app with navigation powered by react-router that I run in development with webpack-dev-server and the history fallback option enabled. H

3条回答
  •  一向
    一向 (楼主)
    2021-02-03 11:05

    @niba's answer perfectly solved my problem. I have been having the problem that when I nest a element inside a component that is already being rendered by a , it will fail to load the script bundle.js when I try to go to a sub-route url. After adding the following in the webpackConfig.json, everything is back to normal.

    module.exports = {
        ...
        output: {
            path: path.resolve('dist'),
            publicPath: '/',
            filename: 'bundle.js'
        },
        ...
    }
    

提交回复
热议问题