Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用webpack编译时,无法在生产环境中刷新页面_Javascript_Node.js_Webpack - Fatal编程技术网

Javascript 使用webpack编译时,无法在生产环境中刷新页面

Javascript 使用webpack编译时,无法在生产环境中刷新页面,javascript,node.js,webpack,Javascript,Node.js,Webpack,我正在使用node.js+express.js+react.js构建一个应用程序,我正在使用webpack编译客户端代码。我遇到的问题是,我的客户端代码是用webpack编译的,我运行我的应用程序后,我无法刷新页面 我的代码: 我的网页将我的文件编译成/dist/index.html,我的应用程序运行在端口3000上,所有客户端路由都以/admin作为前缀 app.get('/', function(req, res) { res.render('dist/index.html');

我正在使用node.js+express.js+react.js构建一个应用程序,我正在使用webpack编译客户端代码。我遇到的问题是,我的客户端代码是用webpack编译的,我运行我的应用程序后,我无法刷新页面

我的代码:

我的网页将我的文件编译成
/dist/index.html
,我的应用程序运行在端口3000上,所有客户端路由都以
/admin
作为前缀

 app.get('/', function(req, res) {
    res.render('dist/index.html');
});
当我在浏览器中转到
localhost:3000
并单击链接时,应用程序运行良好。但是,例如,如果我转到
关于
页面:

localhost:3000/admin/about

当我刷新时,我得到错误
无法获取/admin/about

我相信原因是我的快速路由器只知道
/
路线。。。因此,如果我直接刷新到一个路径,如
/admin/about
,express不知道渲染什么,因此我的解决方案是包含一个“全面覆盖”路径:

但是,这不断给我带来
错误:无法查找视图“dist/index.html”
错误

有人能帮忙吗


提前谢谢

经过研究,我发现解决方案不是
res.render
,而是
res.sendFile


res.sendFile(path.join(uu dirname,'/dist/index.html')

经过研究,我发现解决方案不是
res.render
,而是
res.sendFile

res.sendFile(path.join(uu dirname,'/dist/index.html')

app.get('*', function(req, res) {
  res.render('dist/index.html');
});