我的应用在Webpack开发服务器中工作正常。现在,我想将其部署到生产服务器上。因此,我已经构建了bundle.js文件。我尝试在Express服务器上提供该文件,但我无法访问除根/
以外的其他URL。
例如,这是我的React路由:
var Routes = () => (
<Router history={browserHistory}>
<Route path="/" component={Landing}>
</Route>
<Route path="/app" component={App}>
</Route>
</Router>
)
并且 express 应用程序 (我将 bundle.js
和 index.html
放在 ./public
中):
app.use(express.static('./public'));
app.listen(port, function () {
console.log('Server running on port ' + port);
});
首页 http://localhost:3000/ 可以访问,但是应用 http://localhost:3000/app 无法访问。相反,我收到了一个错误 Cannot GET /app
。
,
'public/index.html')); - Komsit Prakobphol