React Router v4 nested routes not work with webpack-dev-server

后端 未结 5 1260
感情败类
感情败类 2021-01-13 06:50

I try to setup nested routes for my react app like this

  • / -> Home Page
  • /about -> About Page
  • /protected
5条回答
  •  情书的邮戳
    2021-01-13 07:13

    To summarized the answer by @Bing Lu, in your webpack.config.js file:

    module.exports = () => ({
      mode: 'development',
      entry: ...,
      ...,
      output: {
        ...
        publicPath: '/' // <- this is the important line along with historyApiFallback = true in the dev server config
      },
      ...,
      devServer: {
        contentBase: path.join(__dirname, 'dist'),
        historyApiFallback: true,
        compress: true,
        ...
      },
    })
    

提交回复
热议问题