尝试将路由从node.js重定向到路由器时遇到问题。
app.get('*', (req,res) => {
res.sendFile(path.resolve(__dirname + '../client/build/index.html'));
});html
我的浏览器说:
Error: ENOENT: no such file or directory, stat '/home/node/app../client/build/index.html'
顺便问一下,__ dirname是做什么的?
答案 0 :(得分:1)
你应该使用这样的东西......
path.resolve(__ dirname,' ../',' client / build / index.html')
**Like Explained here**
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
{
if the current working directory is /home/myself/node,
this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'
}