React-router “Cannot GET /*” except for root url

前端 未结 5 1720
春和景丽
春和景丽 2020-12-09 02:41

I am willing to use React-router for my application, and I am trying the example given in the doc first, which I copied below. Now when I go to localhost:3000/,

5条回答
  •  执笔经年
    2020-12-09 03:17

    If you are using webpack-dev-server there is an option called history-api-fallback. If set to true 404s will fallback to /index.html.

    Add the option to devServer section of the Webpack config like this:

    devServer: {
        contentBase: 'app/ui/www',
        devtool: 'eval',
        hot: true,
        inline: true,
        port: 3000,
        outputPath: buildPath,
        historyApiFallback: true,
    },
    

    Link to Webpack docs: https://webpack.github.io/docs/webpack-dev-server.html

提交回复
热议问题