我正在开发 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
},
}
我在尝试运行我的构建包时遇到了这个错误。但是当我运行 npm start
时,它运行得很好。
(运行构建应用程序时得到 404)
最佳答案
如果您在服务器上运行它,很可能服务器配置与 url 匹配,并且响应 404 而没有反应。
关于javascript - 硬刷新时找不到页面 - Reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57768441/