通常发生的是当浏览器请求javascript文件时,服务器发送一个html文件.这是由于规则app.get('*'...
.所以我们需要告诉服务器先发送静态文件,然后声明规则,如下所示:
// Declare static folder to be served. It contains the js, images, css, etc. app.use(express.static('build')); // Serve the index.html for all the other requests so that the // router in the javascript app can render the necessary components app.get('*',function(req,res){ res.sendFile(path.join(__dirname+'/build/index.html')); //__dirname : It will resolve to your project folder. });