【发布时间】:2018-02-18 00:06:28
【问题描述】:
我正在使用 React 和 Express 构建一个应用程序,并希望路由主要通过 Express 而不是 react-router。
在我构建了 React 应用程序并将 Express 设置为从构建文件夹提供静态文件之后,每个路径都只指向 React 应用程序。例如访问 localhost:3000/test 时,我仍然只得到 React 应用而不是“测试”。
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, './client/build')));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '/client/build', 'index.html'));
});
app.get('/test', function (req, res) {
res.send("testing");
});
app.listen(3000);
【问题讨论】:
标签: javascript reactjs express