我已经构建了一个以创建React应用程序开始的项目。
我试着用快递送去。
它可以工作,但当我尝试进入其他路线时,这些路线不工作,我的反应应用页面是唯一出现的东西。你能解释一下为什么吗?
这是我的密码。
const express = require('express');
const path = require('path');
const app = express();
const router = express.Router();
app.use(express.static(path.join(__dirname, 'build')));
app.use('/', router);
router.get('/api', (req, res) => {
res.send("API endpoints! ;)")
});
router.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(8080, () => {
console.log('Listening on 8080');
})
我在那儿试过解决办法
`express.static()` keeps routing my files from the route
但它不起作用。