我假设您正在使用Webpack。如果是这样,请在您的webpack配置中添加一些内容即可解决该问题。具体来说,
output.publicPath ='/'和
devServer.historyApiFallback =true。这是下面的示例Webpack配置,它同时使用^和为我解决刷新问题。如果您好奇“为什么”,这会有所帮助。
var path = require('path');var HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = { entry: './app/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'index_bundle.js', publicPath: '/' }, module: { rules: [ { test: /.(js)$/, use: 'babel-loader' }, { test: /.css$/, use: [ 'style-loader', 'css-loader' ]} ] }, devServer: { historyApiFallback: true, }, plugins: [ new HtmlWebpackPlugin({ template: 'app/index.html' }) ]};我在这里写了更多关于此的内容- 使用React Router(或客户端路由器的工作方式)修复刷新时出现的“无法获取/
URL”错误



