javascript - 硬刷新时找不到页面 - Reactjs

标签 javascript reactjs webpack

我正在开发 ReactJs 应用程序。当我用力刷新构建页面时,我收到页面未找到 (404) 错误。但它的工作正常(页面路由)点击按钮。

index.js

ReactDOM.render(<Provider store={store}>
    <BrowserRouter>
        <div>
            <div className="wrapper">
                <Switch>
                    <Route path="/" exact component={Home} />
                    <Route path="/profile" component={Profile} />
                    <Route path="/faq" component={Faq} />
                    <Route path="/privacy" component={Privacy} />                    
                </Switch>
            </div>
        </div>
        </BrowserRouter>
</Provider>, document.getElementById('root'));

webpack.config.js

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  devServer: {
    port: 3000,
    historyApiFallback: true
  },
}

browser console

我在尝试运行我的构建包时遇到了这个错误。但是当我运行 npm start 时,它运行得很好。 (运行构建应用程序时得到 404)

最佳答案

如果您在服务器上运行它,很可能服务器配置与 url 匹配,并且响应 404 而没有反应。

关于javascript - 硬刷新时找不到页面 - Reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57768441/

相关文章:

html - React 应用程序不透明度转换在 Chrome 中不起作用

jquery - Angular 2 + Typescript + jQuery + webpack : $ not defined

javascript - css-loader/style-loader 的错误

javascript - AngularJS 和 Webpack 集成

javascript - 使用 Javascript 中的赋值运算符将一个对象设置为另一个对象

javascript - if php 中不显示 javascript

javascript - react-table 在行单击上添加引用

javascript - 使用 javascript 在输入字段中获取选定的下拉值而不是占位符

javascript - 在保留范围链的同时将回调函数作为字符串传递

javascript - jQuery Cycle - 未加载 img 幻灯片,正在重新排队幻灯片