NodeJs sendFile没有加载webpack包

时间:2018-03-21 11:46:41

标签: javascript node.js reactjs express webpack

我正在使用react和webpack捆绑文件并将其链接到index.html,就像这样,          

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo react</title>
    <link rel="shortcut icon" href="filer/DL_Logo.svg" type="image/svg">
</head>

<body>
    <h1>Hello this is kinda working...</h1>
    <div id="container"></div>
    <script src="/dist/bundle.js" type="text/javascript"></script>
    <!-- Resource jQuery -->
</body>

</html>

当我输入标准网址时这是有效的,因为快递会自动找到index.html并加载它。但是,如果我尝试将res.SendFile用于index.html文件,它只会加载html内容,即H1标记,但不显示放在包内的其余反应内容。 这是有效的(自动查找index.html),

app.use(express.static(__dirname + '/public'));

这不起作用

res.sendFile(__dirname+ "/public/index.html")

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。这个问题不是在节点中,但实际上在你的反应路由器和你的路径中呈现组件。你的路径是错误的,或者你有“精确”的路径,如果它不是那个网址就会停止渲染。